i have the data x.1>x.1 <- data.frame(income=runif(100)*10000,+ edu=sample(c('hs','col','none'),100,T),y=rnorm(100)*100) and i want to get : income y col 5526.726 -11.00956 hs 4196.036 -10.03861 none 4308.111 -28.69549 5526.726 is the mean income for col, 4196.036 is the mean income for hs...... -- Department of Sociology Fudan University,Shanghai Blog:http://sociology.yculblog.com
ronggui wrote:> i have the data x.1 > > >>x.1 <- data.frame(income=runif(100)*10000, > > + edu=sample(c('hs','col','none'),100,T),y=rnorm(100)*100) > > and i want to get : > > income y > col 5526.726 -11.00956 > hs 4196.036 -10.03861 > none 4308.111 -28.69549 > > 5526.726 is the mean income for col, 4196.036 is the mean income for hs...... > > >See ?aggregate, ?by and ?tapply E.g.: aggregate(x.1[,c(1,3)], list(x.1[,2]), mean) Uwe Liggges