[R] dataframes and factors

Wolfgang Koller koller2 at fgr.wu-wien.ac.at
Thu Jun 15 13:36:00 CEST 2000


Dear R-List,

I have a dataframe X containing factor f and numeric variable x1, x2, ... I
want to create a new dataframe (or possibly a matrix) that gives statistics
(e.g. sum) for the variables x1, x2, ... in each group defined by factor f.
What is the simplest way to do this?

I tried:
  attach(X)
  Z <- data.frame(f=levels(f),x1=as.vector(lapply(split(x1,f),sum)))

and stumbled on:
  Error in data.frame(f = levels(f), x1 = as.vector(lapply(split(x1, f),  : 
        arguments imply differing number of rows: 5, 1

Help is much appreciated,

Wolfgang Koller


-------------------------------------------------
Wolfgang Koller,  koller2 at fgr.wu-wien.ac.at
Forschungsinstitut für Europafragen
Wirtschaftsuniversitaet Wien
Althanstrasse 39-45, 1090 Vienna, Austria
http://fgr.wu-wien.ac.at/institut/ef/ief-home.htm
-------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list