-----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 - ---- Instituto de Ingenier??a del Conocimiento (http://www.iic.uam.es) Universidad Aut??noma de Madrid -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFDonvRXHsVbn2qIYMRAqi8AJ0X6zOAevAGzMczQ+ahHlVJnUK4ZQCeIDi6 PPB3baK8JNOa3eoIgbmVCdM=WKlt -----END PGP SIGNATURE-----
> 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.How does d look like? Probably d[,"cls"] and d[,x] instead of d["cls"] and d[x] solves your problem. PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html and *give a reproducible example*. Best, Matthias> 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 > > - ---- > Instituto de Ingenier??a del Conocimiento > (http://www.iic.uam.es) > Universidad Aut??noma de Madrid > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.6 (GNU/Linux) > Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org > > iD8DBQFDonvRXHsVbn2qIYMRAqi8AJ0X6zOAevAGzMczQ+ahHlVJnUK4ZQCeIDi6 > PPB3baK8JNOa3eoIgbmVCdM> =WKlt > -----END PGP SIGNATURE----- > > ______________________________________________ > R-help at 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 >
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
----- Original Message -----
From: "Juan Daniel L??pez Serna" <juanda.lopez at iic.uam.es>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, December 16, 2005 9:33 AM
Subject: [R] Help with data.frame and lapply
-----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
- ----
Instituto de Ingenier??a del Conocimiento
(http://www.iic.uam.es)
Universidad Aut??noma de Madrid
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFDonvRXHsVbn2qIYMRAqi8AJ0X6zOAevAGzMczQ+ahHlVJnUK4ZQCeIDi6
PPB3baK8JNOa3eoIgbmVCdM=WKlt
-----END PGP SIGNATURE-----
______________________________________________
R-help at 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
d <- data.frame(x1 = rnorm(100), x2 = rnorm(100), x3 = rnorm(100), cls =
rnorm(100))
dd <- subset(d, sel=-cls)
lapply(paste("lm(cls ~", names(dd), ",data=d)"), function(x)
eval(parse(text=x)))
Juan Daniel L??pez Serna a ??crit :
>-----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
>
>- ----
>Instituto de Ingenier??a del Conocimiento
>(http://www.iic.uam.es)
>Universidad Aut??noma de Madrid
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.6 (GNU/Linux)
>Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
>
>iD8DBQFDonvRXHsVbn2qIYMRAqi8AJ0X6zOAevAGzMczQ+ahHlVJnUK4ZQCeIDi6
>PPB3baK8JNOa3eoIgbmVCdM>=WKlt
>-----END PGP SIGNATURE-----
>
>______________________________________________
>R-help at 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
>
>
>
Maybe Matching Threads
- custom built R will not change BLAS/LAPACK with update-alternatives
- bzlib, pcre and zlib still needed in rules?
- URW Fonts Description in Installation and Administration Manual
- make check fails with default libblas
- URW Fonts Description in Installation and Administration Manual