#构建子集#基本方法使用:[] \ [[]] \ $> x <- 1:10
> x[1][1] 1
> x[!:5]
Error: unexpected ':'in"x[!:"> x[1:5][1] 1 2 3 4 5
> x>5
[1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE
[9] TRUE TRUE
> x[x>5][1] 6 7 8 9 10
> x[x>5 & x<7][1] 6
> x[x<3 | x>7][1] 1 2 8 9 10
> y <- 1:4
> names(y)<- c("a" , "b" , "c" , "d")> y
a b c d
1 2 3 4
> y[2]
b
2
> y["b"]
b
2
#关于作图
> grid(NA , 5 , lwd = 2) #为纵坐标添加网格线
> grid(5 , 5 , lwd = 2) #为横坐标添加网格线
> plot(0 , main = paste(strwrap("This is a really long title that i can not type it properly" , width = 50),collapse = "\n")) #为图形添加比较长的标题
> plot(0 , 0 , xaxt = "n" , type = "n" ,ylim = c(0 ,100) , las =1)
> #坐标y上的数字如何水平放置
> mtext("35" , side = 2 , at = 35 , line = 1 , las = 1) #在Y轴上添加了35这个坐标
设置渐变色彩:
> x <- 1:10; names(x) <- letters[1:10] #给数组取名字
> barplot(x , col = rev(heat.colors(10))) #reverse,颠倒原来的顺序
> barplot(x , col = heat.colors(10)) #对应下图
> #R颜色组函数有rainbow()/heat.colors()/terrain.colors()/topo.colors()/cm.color()/grey()/gay()
缺失值 NaN,是数值型缺失值; NA有类型属性:integer NA , character NA等。 判断是哪种形式的缺失值:is.na() 或 is.nan(),举例如下: