• 【w3】tapply

2020-03-30 11:22:07
tapply 处理分组数据 > str(tapply) function (X, INDEX, FUN = NULL, ..., simplify = TRUE) X is a vector INDEX is a factor or a list of factors (or else they are coerced to factors) > x <- c...
tapply
处理分组数据
> str(tapply)
function (X, INDEX, FUN = NULL, ..., simplify = TRUE)


X is a vector
INDEX is a factor or a list of factors (or else they are coerced to factors)

> x <- c(rnorm(10), runif(10), rnorm(10, 1))
> f <- gl(3, 10)
> f
[1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3
[24] 3 3 3 3 3 3 3
Levels: 1 2 3
> tapply(x, f, mean)
1 2 3
0.1144464 0.5163468 1.2463678


tapply(x, f, mean)
x: 被处理的数据
f：分组
mean：进行的函数操作


展开全文
• factor(), tapply()

2019-10-09 15:13:14
factor(), ordered() tapply() tapply(X, INDEX, FUN = NULL, …, default = NA, simplify = TRUE)

factor(), ordered()

tapply()

tapply(X, INDEX, FUN = NULL, …, default = NA, simplify = TRUE)


展开全文
• R-table和tapply函数

千次阅读 2017-03-22 09:43:44
R-table和tapply函数  (2013-03-15 09:49:23) 转载▼ 标签：  r语言   tapply函数 分类： R语言 table可统计数据的频数 tapply可根据因子、向量和要计算的函数计算 ...


R-table和tapply函数
(2013-03-15 09:49:23)
转载▼

标签：

r语言

tapply函数

分类： R语言

table可统计数据的频数

tapply可根据因子、向量和要计算的函数计算

> class<-c(1,2,3,2,1,2,1,3)

> class
[1] 1 2 3

> c(81,65,72,88,73,91,56,90)->student
> class
[1] 1 2 3 2 1 2 1 3

>factor(class)->class

> tapply(student,class,mean)
1        2        3
70.00000 81.33333 81.00000
> tapply(student,class,min)
1  2  3
56 65 72

> tapply(student,class,max)
1  2  3
81 91 90
> table(class)
class
1 2 3
3 3 2
>


展开全文
• #tapply(参数)：tapply(向量,因子/因子列表,函数/函数名) > x <- c(rnorm(5),runif(5),rnorm(5,1)) > f <- gl(3,5) > f [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 Levels: 1 2 3 > tapply(x,f,mean)...
#对向量的子集进行操作
#tapply(参数)：tapply(向量,因子/因子列表,函数/函数名)

> x <- c(rnorm(5),runif(5),rnorm(5,1))

> f <- gl(3,5)
> f
[1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
Levels: 1 2 3

> tapply(x,f,mean)
1          2          3
-0.5004154  0.4044779  0.9769996

> tapply(x,f,mean,simplify = FALSE)
$1 [1] -0.5004154$2
[1] 0.4044779

...