Skip to content
Prev 314694 / 398502 Next

Need help on dataframe

Well, a rather simple-minded, brute force approach would be to add a factor variable to the data frame and use aggregate on it.

I am sure there are better ways but this will work.

EXAMPLE
###
xx  <-  data.frame(aa =1:24, 
                     b = matrix(sample(c(1,2,3,4,5,6), 72,  replace = TRUE), nrow= 24))
  dd  <-rep(c("a","b"), each= 12)
  
  xx  <-  cbind(dd, xx)
  
  aggregate(xx[,3:5], list(xx$dd), mean)

################

By the way, when supplying data samples a good way is to use the dput command. Try ?dput for information
John Kane
Kingston ON Canada
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!