omerle
2010-Sep-10 08:05 UTC
[R] Data.frames : difference between x$a and x[, "a"] ? - How set new values on x$a with a as variable ?
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 ? 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]]
Petr PIKAL
2010-Sep-10 08:48 UTC
[R] Odp: Data.frames : difference between x$a and x[, "a"] ? - How set new values on x$a with a as variable ?
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 avariable ?> > 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, ??avous 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Ista Zahn
2010-Sep-10 12:53 UTC
[R] Data.frames : difference between x$a and x[, "a"] ? - How set new values on x$a with a as variable ?
Hi, On Fri, Sep 10, 2010 at 4:05 AM, omerle <omerle at laposte.net> wrote:> Hi, > > I got two questions : > > 1st Question > ??? ??? ??? a="S" > ??? ??? ??? b=data.frame(S=3) > ??? ??? ??? do.call(`<-`,list(do.call(`$`,list(b,"S")),5))I think there is some confusion here. Why are you setting a equal to "S" but then never using it?> => How can I put new values on S column having the column name as a variable ?I'm having trouble parsing this. What exactly do you want to do?> > 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 ?I believe b[["S"]] is the same as b$S, b[,"S"] is different. But I have to question your assertion that b$S=list(1:10) "Works". This is a very odd construction (putting a list as an element of a data.frame) and is almost certainly not what you want.> > > 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. > >-- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org