[R] Conditionally swap two columns of a data.frame?
Dan Bolser
dmb at mrc-dunn.cam.ac.uk
Thu Sep 16 14:19:26 CEST 2004
I am doing this a kinda dumb way, and it is apparetnly taking
forever.
I have a data frame with two numeric columns. I want to look at their
correlation, and I am looking at the size ratio between the two.
i.e.
plot(density(data$V1/data$V2))
This kinda gives me a normal curve showing something about the
distribution of the two values.
I want to make sure that V1/V2 is always > 1 ...
for (i in 1:length(row.names(data)) ){
ratioV1V2 <- if(V1>V2) V1/V2 else V2/V1
}
This is a bit of a hack, and is taking forever for some reson (about
40,000 rows in my data.frame).
I would just like to swap the values in the data frame (to put the bigest
first for example), then use the above plot to get what I want.
Should I use the DB backend to the data to make the dump in this way?
(involves some hacky sql)
Considering I am interested in the range of the ratio between V1 and V2,
should I be looking at doing a different analysis?
I am so dumb, any help is appreciated,
Dan.
More information about the R-help
mailing list