Re: [R] Conditional mean for groups, new variables

2014-06-02 Thread arun
Hi, If you want to extract only particular variables, check ?subset, ?Extract. Using my first example: aggregate(MATH~SCHOOLID,rev1, mean)[,-1,drop=FALSE] #  MATH #1 14.5 #2 17.2 #3 13.71429 #4 13.8 # more than one variable res1 <- aggregate(rev1[,-1], list(SCHOOLID=rev1[,1]), mea

Re: [R] Conditional mean for groups, new variables

2014-06-02 Thread arun
Hi, Regarding your first comment, you didn't provide any reproducible example. So I created one with SCHOOLID's as alphabets.  According to your original post, you had a read dataset with 36000 SCHOOLIDs.  Suppose, if I created the SCHOOLIDs using:  length(outer(LETTERS,1:2000,paste,sep="")) #

Re: [R] Conditional mean for groups, new variables

2014-06-01 Thread arun
Hi, May be this helps: set.seed(42) rev1 <- data.frame(SCHOOLID=sample(LETTERS[1:4],20,replace=TRUE), matrix(sample(25, 20*5,replace=TRUE), ncol=5, dimnames=list(NULL, c("MATH", "AGE", "STO2Q01", "BFMJ", "BMMJ"))),stringsAsFactors=FALSE)  res1 <- aggregate(rev1[,-1], list(SCHOOLID=rev1[,1]), m