Tuesday, September 9, 2014

一些问题的理解(1)

1.NA与NULL
x <- c(88,NA,12,168,13)
x
[188 NA 12 168 13
mean(x)
[1NA
mean(x,na.rm=T)#na.rm=T是指NA,remove,TRUE大家理解吧.
[170.25
x <- c(88,NULL,12,168,13)
mean(x)
[170.25
NA指缺失值,NULL指不存在的

2.
i <- 2
1:i-1 # 注意这个地方!是指(1:i)-1
[10 1
1:(i-1)
[11

3.which()

which可以很方便的用来寻找一些符合固定条件的下标,比如我想找x=c(1,2,3,4,5,1,8)这里面第2个等于1的位置:
which(x==1)[2]

No comments:

Post a Comment