[R] Transformation of a variable in a dataframe

David Winsemius dwinsemius at comcast.net
Wed Apr 17 08:02:58 CEST 2013


On Apr 16, 2013, at 10:33 PM, jpm miao wrote:

> HI,
>   I have a dataframe with two variable A, B. I transform the two  
> variable
> and name them as C, D and save it in a dataframe  dfcd. However, I  
> wonder
> why can't I call them by dfcd$C and dfcd$D?

Because you didn't assign them to dfab$C. It's going to be more  
successful if you use:

dfab[["A"]]*2

>
>   Thanks,
>
> Miao
>
>> A=c(1,2,3)
>> B=c(4,6,7)
>> dfab<-data.frame(A,B)
>> C=dfab["A"]*2
>> D=dfab["B"]*3
>> dfcd<-data.frame(C,D)
>> dfcd
>  A  B
> 1 2 12
> 2 4 18
> 3 6 21
>> dfcd$C
> NULL
>> dfcd$A
> [1] 2 4 6
>
> 	[[alternative HTML version deleted]]


David Winsemius, MD
Alameda, CA, USA



More information about the R-help mailing list