To sort rows with missing values in R, you can use the na.last argument of the order() function. Setting na.last = TRUE will sort the missing values to the end of the column, while setting na.last = FALSE will sort them to the beginning.
Here's an example of sorting a data frame called df by a column called col1, where col1 contains missing values represented by NA:
main.r177 chars6 lines
This will return the sorted data frame with missing values in col1 at the end:
main.r72 chars7 lines
Alternatively, setting na.last = FALSE will sort the missing values first:
main.r79 chars3 lines
This will return the sorted data frame with missing values in col1 at the beginning:
main.r72 chars7 lines
gistlibby LogSnag