Le 9/10/2010 15:37, Ista Zahn a écrit : > On Fri, Sep 10, 2010 at 9:22 AM, omerle<ome...@laposte.net> wrote: >>> Message du 10/09/10 14:53 >>> De : "Ista Zahn" >>> A : "omerle" >>> Copie à : r-help@r-project.org >>> Objet : Re: [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 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? >> 1 - Put a list as an element of a data.frame. That's quite convenient for my >> pricing function. > I think this is a really bad idea. data.frames are not meant to be > used in this way. Why not use a list of lists? Since data.frames are lists, why would it be a bad practice? >>>> 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. >> 2 - That's what I want. I figured out just five minutes ago that b[["S"]] >> works because it's the same thing as b$S. >> But I still dont know what is b[,"S"] compared to b[["S"]] > see ?"[" From the help page, there is not much distinction. Maybe I haven't understood all the details...
Ivan -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php [[alternative HTML version deleted]]
______________________________________________ R-help@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.