Re: [R] Choice of data.frame column by index?
Thanks! Joh On Thursday 23 August 2007 12:01:50 you wrote: x[cbind(1:nrow(x), the.vector)] Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Johannes Graumann wrote: Hello, Imagine a data frame like so: Intensity0 Intensity1 1 767432.1 451743.4 2 3998988.0 4642145.0 3 818974.6 552315.8 and a vector like so: [1] 1 2 1 How can I get R to produce a vector that contains the value in one column or the other depending on the vector? The result should look like [1] 767432.1 4642145.0 818974.6 Thanks for any hints! Joh __ R-help@stat.math.ethz.ch 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. signature.asc Description: This is a digitally signed message part. __ R-help@stat.math.ethz.ch 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] Choice of data.frame column by index?
This won't work since it produces a matrix (try this). What should work is x[(1:nrow(x)) + nrow(x)*(v-1)] --- Johannes Graumann [EMAIL PROTECTED] wrote: Thanks! Joh On Thursday 23 August 2007 12:01:50 you wrote: x[cbind(1:nrow(x), the.vector)] Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Johannes Graumann wrote: Hello, Imagine a data frame like so: Intensity0 Intensity1 1 767432.1 451743.4 2 3998988.0 4642145.0 3 818974.6 552315.8 and a vector like so: [1] 1 2 1 How can I get R to produce a vector that contains the value in one column or the other depending on the vector? The result should look like [1] 767432.1 4642145.0 818974.6 Thanks for any hints! Joh __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Choice of data.frame column by index?
Correct, I didn't notice that the coma was inside the cbind(). Sorry... --- Rolf Turner [EMAIL PROTECTED] wrote: On 24/08/2007, at 12:51 PM, Moshe Olshansky wrote: This won't work since it produces a matrix (try this). On the contrary, Patrick's solution is correct. I tried it. It works just fine. cheers, Rolf Turner What should work is x[(1:nrow(x)) + nrow(x)*(v-1)] --- Johannes Graumann [EMAIL PROTECTED] wrote: Thanks! Joh On Thursday 23 August 2007 12:01:50 you wrote: x[cbind(1:nrow(x), the.vector)] Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Johannes Graumann wrote: Hello, Imagine a data frame like so: Intensity0 Intensity1 1 767432.1 451743.4 2 3998988.0 4642145.0 3 818974.6 552315.8 and a vector like so: [1] 1 2 1 How can I get R to produce a vector that contains the value in one column or the other depending on the vector? The result should look like [1] 767432.1 4642145.0 818974.6 Thanks for any hints! Joh __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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. ## Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ## __ R-help@stat.math.ethz.ch 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] Choice of data.frame column by index?
On 24/08/2007, at 12:51 PM, Moshe Olshansky wrote: This won't work since it produces a matrix (try this). On the contrary, Patrick's solution is correct. I tried it. It works just fine. cheers, Rolf Turner What should work is x[(1:nrow(x)) + nrow(x)*(v-1)] --- Johannes Graumann [EMAIL PROTECTED] wrote: Thanks! Joh On Thursday 23 August 2007 12:01:50 you wrote: x[cbind(1:nrow(x), the.vector)] Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Johannes Graumann wrote: Hello, Imagine a data frame like so: Intensity0 Intensity1 1 767432.1 451743.4 2 3998988.0 4642145.0 3 818974.6 552315.8 and a vector like so: [1] 1 2 1 How can I get R to produce a vector that contains the value in one column or the other depending on the vector? The result should look like [1] 767432.1 4642145.0 818974.6 Thanks for any hints! Joh __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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. ## Attention:\ This e-mail message is privileged and confidenti...{{dropped}} __ R-help@stat.math.ethz.ch 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.