Re: [R] Correct subsetting in R

2017-11-02 Thread peter dalgaard
> On 1 Nov 2017, at 18:03 , Elahe chalabi via R-help > wrote: > > But they row.names() cannot give me the IDs > Is "training" extracted from "data" using standard data frame indexing? If so, data[row.names(training), "ID"] should give you the relevant values. If not, then you are in troubl

Re: [R] Correct subsetting in R

2017-11-01 Thread Eric Berger
training$TrainingRownum <- 1:nrow(training) data$DataRownum <- 1:nrow(data) matches <- merge(training,data,by=intersect(names(training),names(data))) The data frame 'matches' now has additional columns telling you the row in each data frame corresponding to the matched items. Regards, Eric On We

Re: [R] Correct subsetting in R

2017-11-01 Thread Elahe chalabi via R-help
It's not what I want, the first data frame has 499 observations and the second data frame is a subset of the first one but with 375 observations. I want something that returns the ID for training data frame On Wednesday, November 1, 2017 10:18 AM, Eric Berger wrote: matches <- merge(tra

Re: [R] Correct subsetting in R

2017-11-01 Thread Elahe chalabi via R-help
But they row.names() cannot give me the IDs On Wednesday, November 1, 2017 9:45 AM, David Wolfskill wrote: On Wed, Nov 01, 2017 at 04:13:42PM +, Elahe chalabi via R-help wrote: > Hi all, > I have two data frames that one of them does not have the column ID: > > > str(data) >

Re: [R] Correct subsetting in R

2017-11-01 Thread Eric Berger
matches <- merge(training,data,by=intersect(names(training),names(data))) HTH, Eric On Wed, Nov 1, 2017 at 6:13 PM, Elahe chalabi via R-help < r-help@r-project.org> wrote: > Hi all, > I have two data frames that one of them does not have the column ID: > > > str(data) > 'data.frame':

[R] Correct subsetting in R

2017-11-01 Thread Elahe chalabi via R-help
Hi all, I have two data frames that one of them does not have the column ID: > str(data) 'data.frame': 499 obs. of 608 variables: $ ID : int 1 2 3 4 5 6 7 8 9 10 ... $ alright : int 1 0 0 0 0 0 0 1 2 1 ... $ bad : int 1 0 0 0 0 0 0 0 0 0 ...