Hi R community, I have been trying to figure out why R is reversing the order of rows after I run data.matrix()
Here is my data: df<-structure(list(itmID = c(1L, 2L, 1L, 2L, 1L, 2L), variable = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("3", "2", "1"), class = "factor"), value = c(0.7, 0.52, -1.16, -0.91, 0, 0)), .Names = c("itmID", "variable", "value"), row.names = c(NA, -6L), class = "data.frame")(NA, -6L), class = "data.frame") The data looks like this now >df itmID variable value 1 1 3 0.70 2 2 3 0.52 3 1 2 -1.16 4 2 2 -0.91 5 1 1 0.00 6 2 1 0.00 however after running data.matrix(df) I get: itmID variable value [1,] 1 1 0.70 [2,] 2 1 0.52 [3,] 1 2 -1.16 [4,] 2 2 -0.91 [5,] 1 3 0.00 [6,] 2 3 0.00 Note, only the order of the column "variable" as been reversed 332211 to 112233, not the order of the other columns. So, the data is now out of order. Any thoughts. What I am doing wrong? Thanks Alexander [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.