[R] Odp: Data.frames : difference between x$a and x[, "a"] ? - How set new values on x$a with a as variable ?

Petr PIKAL petr.pikal at precheza.cz
Fri Sep 10 10:48:57 CEST 2010


Hi

r-help-bounces at r-project.org napsal dne 10.09.2010 10:05:37:

> Hi,
> 
> I got two questions :
> 
> 1st Question
> Â Â Â  Â Â Â  Â Â Â  a="S"
> Â Â Â  Â Â Â  Â Â Â  b=data.frame(S=3)
> Â Â Â  Â Â Â  Â Â Â  do.call(`<-`,list(do.call(`$`,list(b,"S")),5))
> => How can I put new values on S column having the column name as a 
variable ?
> 
> 2 nd Question
> Â Â Â Â Â Â  a="S"
> Â Â Â  Â Â  b=data.frame(S=3)
> Â Â  Â Â Â  b[,"S"]=list(1:10) #Doesnt works
> Â Â  Â Â Â  b$S=list(1:10) #Works
> => Isnt the same thing ? What is the difference between these two things 
?

did you looked at b e.g. by str(b)? I believe you expected something 
different.

Maybe you wanted rbind
rbind(b[,"S"],data.frame(S=1:10))

Regards
Petr

> 
> 
> Thanks,
> 
> Une messagerie gratuite, garantie à vie et des services en plus, ça 
vous tente ?
> Je crée ma boîte mail www.laposte.net
> 
>    [[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.



More information about the R-help mailing list