r - getting mean of variables based on names -


i have vector hu <-rnorm(20) names names(hu) <- c(1:5,1:5,6:10,3:7) how group them can take means based on names?

try

 tapply(hu, names(hu), fun=mean) 

if need in order 1:10, convert names(hu) 'character' 'numeric'

 tapply(hu, as.numeric(names(hu)), fun=mean) 

or

  unique(ave(hu, names(hu))) 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -