Hi Simon, i tried your code, but it results in an error:
"error in var(x) : `x` is empty" Do you have an idea what the reason might be? Thanks a lot, Henning > > -------- Original-Nachricht -------- > Datum: Fri, 18 Jul 2008 11:37:24 +0100 > Von: Simon Anders <[EMAIL PROTECTED]> > An: Henning Wildhagen <[EMAIL PROTECTED]> > CC: r-help@r-project.org > Betreff: Re: [R] t-test for multiple variables > > Hi Henning, > > Henning Wildhagen wrote: > > Given a dataframe of three columns, where col1 is of type factor, col 2 > and > > col3 are numeric and pairs of observations i would like to perform a > paired > > t-test for each level of col1. > > I would like to avoid specifying the levels of col1 manually because it > > seems to me as being stupid, however, i did not figure out how to tell > it R > > in an function. I tried with tapply, but it did not work. > > That's what 'tapply' is meant for. Try this: > > tapply( 1:nrow(df), df$col1, function(r) > t.test( df$col2[r], df$col3[r], paired=TRUE ) ) > > Here, tapply calls the fucntion in the second line for each level of > col1, always passing the row indices of the rows with this level as > parameter 'r'. > > HTH > Simon > -- Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.