Re: [R] Efficient way to create new column based on comparison with another dataframe

2016-01-31 Thread Gaius Augustus
ot;S3"), Chr = 1, Position = c(3000, 6000, > 1000), key = "Chr") instead of data.frame(Name = c("S1", "S2", "S3"), Chr = > 1, Position = c(3000, 6000, 1000), key = "Chr"). > > HTH, > Denes > > > > On 01/30/2016 0

Re: [R] Efficient way to create new column based on comparison with another dataframe

2016-01-30 Thread Gaius Augustus
cur.row <- Chr.Arms[i, ] mapfile$Arm[ mapfile$Chr == cur.row$Chr & mapfile$Position >= cur.row$Start & mapfile$Position <= cur.row$End] <- cur.row$Arm } This took out the need for the intermediate table/vector. This worked for me, and was VERY fast. Took <5 minutes on a

Re: [R] Efficient way to create new column based on comparison with another dataframe

2016-01-30 Thread Gaius Augustus
ly(Chr.Arms, .variables = "Arm", function(cur.row, mapfile){ > mapfile <- mapfile[ Position >= cur.row$Start & Position <= cur.row$End] > mapfile <- mapfile[ , Arm:=cur.row$Arm][] > return(mapfile) > }, mapfile = mapfile) > > I have just started to u

[R] Efficient way to create new column based on comparison with another dataframe

2016-01-29 Thread Gaius Augustus
I have two dataframes. One has chromosome arm information, and the other has SNP position information. I am trying to assign each SNP an arm identity. I'd like to create this new column based on comparing it to the reference file. *1) Mapfile (has millions of rows)* NameChr Position S1