I started learning R a couple of weeks ago, so I'm still very very new to R coding; I was trying to order a dataframe numerically, but on top of the ordered dataframe, resulted from the execution of the function order(nameofthedataframe), it appears "Warning in xtfrm.data.frame(x) : cannot xtfrm data frames". Could please anyone tell me what did I do wrong?
Thank you very much!
Examples:
order(iris[,"Petal.Width"]) # this seems fine
order(iris[,"Petal.Width",drop=FALSE]) # warning
order(iris[,c("Petal.Width","Sepal.Width")]) # warningR version 4.1.0
13 Answers
I am using the R version 4.1.0 and it seems like the order() function comes with an error check as you pointed out. You may still try using the order() function as follows,
order(dataframe[,"column"])Here is a link to an alternative method in an article titled "It Has Always Been Wrong to Call order on a data.frame" by jmount 1
I recieved the same error while trying to perform a panelvarmodel in R4.3.0. Despite I read many comments and suggestion, nothing worked. In my case the cause was not related to any kind of sort/order/ type of data eg. character/numeric. panelvar:pvargmm uses a particular structure of data defined by date_id x crossection_id (eg. year x countries). Before use a dataframe as source for panelvar analysis, I suggest to use plm package and to define a panel structure. The short code should look like: plm::pdata.frame(datframe_source, index=c("crossection_id","date_id")).
a better idea is to convert a dataframe into a matrix by using as.matrix and then after sorting re-convert it to dataframe.