[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]] __ 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.
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 ome...@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@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 __ 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.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?
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.  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]] 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@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 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@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.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?
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? 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 ?[ 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@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 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@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 __ 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.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as 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? It can be very convenient, but I suspect the original poster is confused about the different between vectors and lists. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?
Le 9/10/2010 15:37, Ista Zahn a écrit : On Fri, Sep 10, 2010 at 9:22 AM, omerleome...@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.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?
On Sep 10, 2010, at 9:42 AM, Hadley Wickham wrote: 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? It can be very convenient, but I suspect the original poster is confused about the different between vectors and lists. I wouldn't be surprised if someone were confused, since my reading of some (but not all) of the help documents has led me to think that lists _were_ vectors, just not vectors of atomic mode. And one oft- illustrated method for creating a list is: alist - vector(mode=list, length=10). I am perhaps less confused than I was two years ago but my confusion about all the possible permutations of mode, typeof, expression, formula, and class and the extraction methods therefrom definitely persists. I think the authors of the documentation are of divided opinion or usage on this topic. Best; David. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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. David Winsemius, MD West Hartford, CT __ 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.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?
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? It can be very convenient, but I suspect the original poster is confused about the different between vectors and lists. I wouldn't be surprised if someone were confused, since my reading of some (but not all) of the help documents has led me to think that lists _were_ vectors, just not vectors of atomic mode. And one oft-illustrated method for creating a list is: alist - vector(mode=list, length=10). I am perhaps less confused than I was two years ago but my confusion about all the possible permutations of mode, typeof, expression, formula, and class and the extraction methods therefrom definitely persists. I think the authors of the documentation are of divided opinion or usage on this topic. I probably should have said atomic vectors - it's easy to get confused when you fail to be specific. Data frames add even more confusion: is.vector(as.vector(mtcars)) [1] FALSE (That behaviour matches the documentation, but it's still confusing!) Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?
Well, let's see if the following helps or just adds to the confusion. First lists are vectors of mode list . But they are general recursive structures (in fact, completely general). Second, data frames are lists: each column of a data frame is a component (member) of the list with the additional requirement that all the components must be the same length. The reason for the scare quotes areound column will become clear shortly. Now, for examples: x - data.frame(a=1:3,b=list(c=4:6)) x a c 1 1 4 2 2 5 3 3 6 ## This is as documented in ?data.frame. ## Now compare: y - data.frame(a=1:3) y$b - list(c=4:6) y a b 1 1 4, 5, 6 2 2 4, 5, 6 3 3 4, 5, 6 ## A different result that one might think should be the same as the previous one. What's going on is: y is a data frame, so all components must have the same length. Because the length of b, a list, is just 1, it is replicated to be the proper length: y$b $c [1] 4 5 6 $c [1] 4 5 6 $c [1] 4 5 6 ##The b component is still a list: mode(y$b) [1] list ## of course: y$c=7:9 y a b c 1 1 4, 5, 6 7 2 2 4, 5, 6 8 3 3 4, 5, 6 9 ## This is correct, since the c component is a vector of length 3. Note also: mode(y[,3]) [1] numeric mode(y[[3]]) [1] numeric mode(y[3]) [1] list ## All these are correct = agree with documented behavior of [ and [[ because a data.frame IS a list. Cheers, Bert On Fri, Sep 10, 2010 at 7:13 AM, David Winsemius dwinsem...@comcast.net wrote: On Sep 10, 2010, at 9:42 AM, Hadley Wickham wrote: 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? It can be very convenient, but I suspect the original poster is confused about the different between vectors and lists. I wouldn't be surprised if someone were confused, since my reading of some (but not all) of the help documents has led me to think that lists _were_ vectors, just not vectors of atomic mode. And one oft-illustrated method for creating a list is: alist - vector(mode=list, length=10). I am perhaps less confused than I was two years ago but my confusion about all the possible permutations of mode, typeof, expression, formula, and class and the extraction methods therefrom definitely persists. I think the authors of the documentation are of divided opinion or usage on this topic. Best; David. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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. David Winsemius, MD West Hartford, CT __ 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. __ 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.