[R] Adding new columns to (output) data - e.g., read 5 cols write 8

Esmail Bonakdarian esmail.js at gmail.com
Thu Jun 12 04:49:06 CEST 2008


Hi Erik,

Erik Iverson wrote:
> Esmail -
> 
> Are these 5 vectors of data stored in a data.frame?  I assume so.

Yes, I do a simple load() call first to read the .rda file ...

> test2 <- transform(test, d = 2*a + b, e = 3*c)
> save(test2, file = "test2.Rdata")
> 
> Does this help?

Yes it does .. this is just what I needed. I'll probably do it
in this way:

df=transform(df, X5=X1+X2)
df=transform(df, X6=X1-X2)
etc ...


building it up the df line by line since the definitions have been
provided one per line (instead of queuing them up in one line like
you showed). I'll have to write a  little awk or ruby script to take
the original definitions and wrap them into the transform call, but then
I should be all set to go.

Thanks again!

Esmail



More information about the R-help mailing list