[R] data frame question

Gabor Csardi csardi at rmki.kfki.hu
Thu Feb 14 18:16:15 CET 2008


df2 = df 

?

G.

On Thu, Feb 14, 2008 at 09:12:23AM -0800, joseph wrote:
> 
> 
> Hi
> 
> I have a data frame df1 in which I would like to multiply col1
> by 2.
> 
> 
> The way I did it does not allow me to keep the old data
> frame.
> 
> 
> How can I do this and be able to create a new data frame
> df2?
> 
> 
> > df1= data.frame(col1= c(3, 5, NA, 1), col2= c(4, NA,6,
> 2))
> 
> 
> > df1
> 
> 
>   col1 col2
> 
> 
> 1    3    4
> 
> 
> 2    5   NA
> 
> 
> 3   NA    6
> 
> 
> 4    1    2
> 
> 
> > df1$col1=df1$col1*2
> 
> 
> > df1
> 
> 
>   col1 col2
> 
> 
> 1    6    4
> 
> 
> 2   10   NA
> 
> 
> 3   NA    6
> 
> 
> 4    2    2
> 
> 
> 
> 
> 
>       ____________________________________________________________________________________
> Be a better friend, newshound, and 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

-- 
Csardi Gabor <csardi at rmki.kfki.hu>    UNIL DGM



More information about the R-help mailing list