Thank you to all for your ideas. They all solved my problem nicely.
And I learned about paste() too!
--Chris
Christopher W. Ryan, MD
SUNY Upstate Medical University Clinical Campus at Binghamton
40 Arch Street, Johnson City, NY 13790
cryanatbinghamtondotedu
PGP public keys available at http://ho
May be this helps:
jaw<-data.frame(vara=1:20,age=runif(20))
for (i in 2:6) {
jaw[paste("agepow",i, sep="")] <- jaw["age"]^i
}
jaw<-round(jaw,2) # It is just to help the check task
Cheers,
Miltinho Astronauta
Brazil
On 7/14/08, Christopher W. Ryan <[EMAIL PROTECTED]> wrote:
>
> R
Christopher W. Ryan wrote:
R 2.5.1 on WinXP
I'm trying to create new variables in a dataframe called jaw, as powers
of jaw$age up to the sixth power, and name them
jaw$age.(--the digit corresponding to the power--)
Obviously none of these work (silly for me to try, I suppose):
for (i in 2:6)
R 2.5.1 on WinXP
I'm trying to create new variables in a dataframe called jaw, as powers
of jaw$age up to the sixth power, and name them
jaw$age.(--the digit corresponding to the power--)
Obviously none of these work (silly for me to try, I suppose):
for (i in 2:6) {
jaw$age.'i' <- jaw$age^i
4 matches
Mail list logo