[R] How to order based on the second two columns?

Andra Isan andra_isan at yahoo.com
Mon Aug 29 20:40:35 CEST 2011


Hello All, 

I have a data frame consisting of 4 columns (id1, id2, y, pred)
where pred is the predicted value based on the glm function and my data frame is called "all". "data" is another data frame that has all data but I want to put together some important columns from my original data frame (data) into another data frame (all) as follows and I would like them to be sorted based on the id1 and id2. Here is what I do:

all_data = cbind(oder(data[,2]), order(data[,3]), data[,1], pred)
all = as.data.frame(all_data)
colnames(all) = c("id1", "id2", "y" , "pred")

when I do the ordering thing, I am not sure why I do not get the corresponding "y" and "pred" values for that specific row after ordering. Am I doing something wrong in here?

Thanks a lot,
ANDRA



More information about the R-help mailing list