Warning in xtfrm.data.frame(x) : cannot xtfrm data frames: error while ordering a dataframe numerically in R
Asked Answered
B

5

9

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")]) # warning

R version 4.1.0

Bourassa answered 23/6, 2021 at 13:56 Comment(1)
Please share data or sample of your data in a reproducible format and also include the code that you are using. Read about how to give a reproducible exampleCrowning
V
5

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

Vitals answered 5/7, 2021 at 20:35 Comment(0)
S
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")).

Sawhorse answered 31/10, 2023 at 15:56 Comment(0)
G
0

I solved using arrange(dataset, desc(variable1), variable2) from dplyr package

Gnome answered 1/2, 2024 at 16:16 Comment(0)
G
0

Instead order(dataframe[,"column"]) try using order(dataframe$column)

Granite answered 31/7, 2024 at 12:45 Comment(0)
A
-3

a better idea is to convert a dataframe into a matrix by using as.matrix and then after sorting re-convert it to dataframe.

Aubigny answered 10/8, 2022 at 9:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.