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

From: Erik Iverson <iverson_at_biostat.wisc.edu>
Date: Wed, 11 Jun 2008 20:48:26 -0500

Esmail -

Esmail Bonakdarian wrote:
> Hello, I have the following task I'd like to accomplish:
>
> A file contains 5 columns of data (several hundred rows), let's call
> them a, b, c, d and e (ie these are their column headers)

Are these 5 vectors of data stored in a data.frame? I assume so.

>
> I also have a set of definitions, e.g.,
>
> f = a + b
> g = a * 3
> h = c + d
> etc.
>
> I would like to write out a new .rda file that contains columns
>
> a b c d e f g h etc.
>
> I.e. , the original data plus new columns (with headers and data).

Example,

test <- data.frame(a = 1:10, b = 2:11, c = 3:12) test2 <- transform(test, d = 2*a + b, e = 3*c) save(test2, file = "test2.Rdata")

Does this help?

Best,
Erik Iverson



R-help_at_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. Received on Thu 12 Jun 2008 - 03:15:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 Jun 2008 - 03:30:53 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive