Try R

Try R

我知道我是个懒人,突然间就不想写博客了,停了差不多三个月,现在可以重新开始了:


Chapter 1

try some simple math

R is a language and environment for statistical computing and graphics,It’s an open source solution to data analysis that’s supported by a large and active worldwide research community.

Expressions 1.1
> 1 + 1
[1] 2
> "Arr, matey!"
[1] "Arr, matey!"
> 6 * 7
[1] 42
Logical Values 1.2
> 3 < 4
[1] TRUE
> 2 + 2 == 5
[1] FALSE
> T == TRUE
[1] TRUE 
# T and F are shorthand for TRUE and FALSE.
Variables 1.3
> x <- 42
# Type x <- 42 to store a value in x.
> x / 2
[1] 21
> x <- "Arr, matey!"
> x
[1] "Arr, matey!"
> x <- TRUE
# assigning the TRUE logical value to x
Functions 1.4
# sum
> sum(1, 3, 5)
[1] 9
# rep
# time
> rep("Yo ho!", times = 3)
[1] "Yo ho!" "Yo ho!" "Yo ho!"
# sqrt
> sqrt(16)
[1] 4
Help 1.5
> help(sum)
sum {base}  R Documentation
Sum of Vector Elements

Description
sum returns the sum of all the values present in its arguments.

Usage
sum(..., na.rm = FALSE)

Arguments
... 
numeric or complex or logical vectors.
na.rm   
... 
> example(min)
min> require(stats); require(graphics)
min>  min(5:1, pi) #-> one number
[1] 1
min> pmin(5:1, pi) #->  5  numbers
[1] 3.141593 3.141593 3.000000 2.000000 1.000000
min> x <- sort(rnorm(100));  cH <- 1.35
min> pmin(cH, quantile(x)) # no names
[1] -2.4918436 -0.9161651 -0.1945227  0.4487425  1.3500000
min> pmin(quantile(x), cH) # has names
        0%        25%        50%        75%       100% 
-2.4918436 -0.9161651 -0.1945227  0.4487425  1.3500000 
min> plot(x, pmin(cH, pmax(-cH, x)), type = "b", main =  "Huber's function")
Hit <Return> to see next plot:  
min> cut01 <- function(x) pmax(pmin(x, 1), 0)
min> curve(      x^2 - 1/4, -1.4, 1.5, col = 2)

这里写图片描述

Hit <Return> to see next plot: 

min> curve(cut01(x^2 - 1/4), col = "blue", add = TRUE, n = 500)

min> ## pmax(), pmin() preserve attributes of *first* argument
min> D <- diag(x = (3:1)/4) ; n0 <- numeric()

min> stopifnot(identical(D,  cut01(D) ),
min+           identical(n0, cut01(n0)),
min+           identical(n0, cut01(NULL)),
min+           identical(n0, pmax(3:1, n0, 2)),
min+           identical(n0, pmax(n0, 4)))

这里写图片描述

> help(rep)
rep {base}  R Documentation
Replicate Elements of Vectors and Lists
Description
rep replicates the values in x. It is a generic function, and the (internal) default method is described here.
rep.int and rep_len are faster simplified versions for two common cases. They are not generic.
Usage
rep(x, ...)
rep.int(x, times)
rep_len(x, length.out)
Files 1.6
> list.files()
 [1] "1.png"                "123.xlsx"             "1234.xlsx"           
 [4] "Bluetooth 交换文件夹" "desktop.ini"          "down"                
 [7] "GIS DataBase"         "IISExpress"           "JDdongdong"          
[10] "My eBooks"            "My Music"             "My Pictures"         
[13] "My Videos"            "My Web Sites"         "OneNote 笔记本"      
[16] "OriginLab"            "R"                    "ServerConfig"        
[19] "Tencent Files"        "VisIt"                "Visual Studio 2013"  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值