Re: [R] Help with data.frame and lapply

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Fri 16 Dec 2005 - 19:54:37 EST

you could use something like:

d <- data.frame(x1 = rnorm(100), x2 = rnorm(100), x3 = rnorm(100), cls = rnorm(100))
lapply(d[-match("cls", names(d))], function(x, y) lm(y ~ x), y = d$cls)

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello:
I'm having problems with this line of code:

X.lm <- lapply(names(d), function(x) lm(d["cls"] ~ d[x], data=d))

d[x] is what is giving trouble here, but I don't know exactly how to solve it. What I'm trying to do is to create a linear model from each column of the data frame 'd' to apply ANOVA later. Thanks very much in advance. Regards:

Juan Daniel López Serna

iD8DBQFDonvRXHsVbn2qIYMRAqi8AJ0X6zOAevAGzMczQ+ahHlVJnUK4ZQCeIDi6 PPB3baK8JNOa3eoIgbmVCdM=
=WKlt
-----END PGP SIGNATURE-----



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Dec 16 19:57:40 2005

This archive was generated by hypermail 2.1.8 : Fri 16 Dec 2005 - 20:32:46 EST