Strange behavior when using apply with rank and order on a data.frame with ordered factors

前端 未结 2 1155
孤城傲影
孤城傲影 2021-01-23 22:23

I\'ve found some weird behavior with apply.

Assume I have an arbitrary matrix of ordered variables

set.seed(4)
x <- ordered(sample(1:10,          


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-23 22:49

    I am not sure why the extract reason for that happen to apply function. But you could try sapply to solve the problem.

    rankmat3 <- as.data.frame(sapply(data1, rank))
    
    The result would be like:
    rankmat3
        x y z
    1 4.0 3 4
    2 1.0 1 1
    3 2.5 2 3
    4 2.5 4 2
    

提交回复
热议问题