[R] How to order based on the second two columns?
David Winsemius
dwinsemius at comcast.net
Mon Aug 29 20:42:41 CEST 2011
On Aug 29, 2011, at 2:40 PM, Andra Isan wrote:
> 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?
Your error is in not using 'merge' instead of 'cbind'.
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list