The R Book exemple Matrix and aggregate() -
The R Book exemple Matrix and aggregate() -
good evening,
i using "the r book" michael j. crawley. understand not best book learning r... have.
so in chapter 2 explain calculations on rows , columns. out of came question.
here series of command in r (r-studio) , have simple question ask.
x <- matrix(rpois(20, 1.5), nrow=4) x # [,1] [,2] [,3] [,4] [,5] #[1,] 2 2 0 0 2 #[2,] 2 1 0 0 2 #[3,] 1 0 1 2 0 #[4,] 2 1 2 0 2 grouping = c("a", "b", "b", "a") aggregate(x, list(group), sum) # ************** # group.1 v1 v2 v3 v4 v5 #1 4 3 2 0 4 #2 b 3 1 1 2 2
the question how did column titles (*) did appeared ...
v1 vector 1, v2 vector 2 ...
is intrinsic function aggregate()?
cheers
claude
from ?aggregate
:
"the default method... coerces ‘x’ info frame , calls info frame method."
as.data.frame(x)
gives vn
column names:
as.data.frame(x) # v1 v2 v3 v4 v5 #1 0 1 1 0 2 #2 1 3 2 1 1 #3 1 3 2 0 0 #4 3 2 2 1 1
r
Comments
Post a Comment