I have the following example data frame in R.
item index ptr
A 1 0.40
B 2 NA
C 3 0.30
D 4 0.35
E 5 0.44
F 6 NA
It is already sorted based on column = index. Now, I would like to sort it by the column ptr but by leaving the position of rows where ptr = NA intact. So the output I’m expecting is:
item index ptr
C 3 0.30
B 2 NA
D 4 0.35
A 1 0.40
E 5 0.44
F 6 NA
The regular df = df[order(ptr),] doesn’t work. Any ideas? Thanks much in advance.
try this: