Move NAs to the end of each column in a data frame

后端 未结 4 1633
生来不讨喜
生来不讨喜 2020-12-04 01:30

I have such a data frame:

df <- structure(list(a = c(NA, NA, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), b = c(NA, NA, NA, 1L, 2L, 3L, 4L, 5L, 6L, 7L), d = c(NA, NA,          


        
4条回答
  •  误落风尘
    2020-12-04 02:17

    If you got small number of columns, I suggest:

    data.frame( a=sort(example$a, na.last=T), b=sort(example$b, na.last=T), d=sort(example$d, na.last=T))
    

    Best, Adii_

提交回复
热议问题