『Data Science』R语言学习笔记,基础语法
| 
 
 > str(apply) function (X,MARGIN,...) 
 > x <- matrix(1:4,2)
> x
     [,2]
[1,]    1    3
[2,]    2    4
> apply(x,mean)
[1] 2 3
> apply(x,mean)
[1] 1.5 3.5
 Other shortcuts. 
 Apply in multiple dimensions array,in the source below,we use a vector as a MARGIN value to complete the compute of multiple dimensions compute. > a <- array(rnorm(2 * 2 * 10),c(2,10))
> apply(a,c(1,mean)
           [,1]        [,]  0.6869065 -0.66529430
[2,] -0.1136978 -0.04124547mapply
 > str(mapply) function (FUN,...,MoreArgs = NULL,SIMPLIFY = TRUE,USE.NAMES = TRUE) 
 tapply
 split
 > s <- split(airquality,airquality$Month)
> sapply(s,function(x) colMeans(x[,c("Ozone","Wind")]))
             5        6        7        8     9
Ozone       NA       NA       NA       NA    NA
Wind  11.62258 10.26667 8.941935 8.793548 10.18(编辑:我爱故事小小网_铜陵站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 


 浙公网安备 33038102330570号
 浙公网安备 33038102330570号