[R] creating column based on another variable

John Kane jrkrideau at yahoo.ca
Mon Dec 4 16:08:55 CET 2006


--- Jeff Miller <jeffmiller at adsam.com> wrote:

> Hi all,
> 
> I hope someone can help me with this.

> Suppose I import a text file and one of the columns
> looks like this:
> 
> New York
> 
> New York
> 
> England
> 
> Spain
> 
> Spain
> 
> Orlando
> 
> New York
> 
> England
> 
> France
> 

> I want to add a variable that is based on the
> previous one
> 
>  
> 
> US
> 
> US
> 
> Europe
> 
> Europe
> 
> Europe
> 
> US
> 
> US
> 
> Europe
> 
> Europe
> 
> How do that?

?cbind

> Also, I would like to be able to export the data as
> a text file that retains
> this new variable.

> Any suggestions are greatly appreciated,
 
> Jeff Miller

?write.table
?write.csv

It might be a good idea to read a bit about how R
works.  A handy tutorial is 
http://www.math.ilstu.edu/dhkim/Rstuff/Rtutor.html

and you should have a look at the FAQ and the Intro to
R   both available the main R site
http://www.r-project.org/




More information about the R-help mailing list