[R] Quick R syntax question

2011-06-20 Thread Ben Ganzfried
Hi -- I had a pretty quick R question since unfortunately I have not been able to find an answer on Google. It shouldn't take much more than a minute to answer. I'm trying to add up the major gleason grade and minor gleason grade for an analysis of patients with prostate cancer. One column has

Re: [R] Quick R syntax question

2011-06-20 Thread Luke Miller
If we assume that your data are in a data frame (which doesn't allow spaces in column names, hence the periods in the call below): df = data.frame(Major.Gleason = c(4,5,2,3), Minor.Gleason = c(3,2,4,3)) You can paste together the contents of the two columns with a plus sign in between using the

Re: [R] Quick R syntax question

2011-06-20 Thread David Winsemius
On Jun 20, 2011, at 11:47 AM, Luke Miller wrote: If we assume that your data are in a data frame (which doesn't allow spaces in column names, hence the periods in the call below): df = data.frame(Major.Gleason = c(4,5,2,3), Minor.Gleason = c(3,2,4,3)) You can paste together the contents

Re: [R] Quick R syntax question

2011-06-20 Thread Ben Ganzfried
Thanks! Very glad you pointed me to the paste function, it looks very helpful. I have a quick follow-up after reading through the online tutorial on the paste function: Why do we need quotation marks around Major Gleason and Minor Gleason in: output = paste(df [,'Major.Gleason'], df[

Re: [R] Quick R syntax question

2011-06-20 Thread Luke Miller
The quotes around 'Major.Gleason' and 'Minor.Gleason' are required for accessing data frame columns by name. You could alternately refer to the columns by number if you're sure you know which column is which: output = paste(df[ ,1], df[ ,2], sep = '+') It's just a requirement for accessing

Re: [R] Quick R syntax question

2011-06-20 Thread Bert Gunter
Ben: 1. One doesn't ask questions like this. Syntax is syntax. 2. This has nothing to do with paste; it's the syntax of [ , subscripting/extraction 3. But it does make sense: a - b z - data.frame(a=1:3, b=4:6) z[ ,a] # the a column of z z[ ,a] # the column of z with the value of the object

Re: [R] Quick R syntax question

2011-06-20 Thread Bert Gunter
Sorry, I was unclear. The comment after the second should be: z[ ,a] # the column of z whose name is the value of the object a -- Bert On Mon, Jun 20, 2011 at 9:38 AM, Bert Gunter bgun...@gene.com wrote: Ben: 1. One doesn't ask questions like this. Syntax is syntax. 2. This has nothing

Re: [R] Quick R syntax question

2011-06-20 Thread Ben Ganzfried
Thanks for the clarifications. On Mon, Jun 20, 2011 at 12:40 PM, Bert Gunter gunter.ber...@gene.comwrote: Sorry, I was unclear. The comment after the second should be: z[ ,a] # the column of z whose name is the value of the object a -- Bert On Mon, Jun 20, 2011 at 9:38 AM, Bert Gunter