r - Why does reordering turn single column data frames into vectors? -


i curious why reordering single columned data frame (or matrix) converts vector. there reason this?

k <- data.frame(a=c(2,10,3), b=c(8,3,9)) k <- k[order(k[,1]),] class(k) # [1] "data.frame"  k <- data.frame(a=c(2,10,3)) k <- k[order(k[,1]),] class(k) # [1] "numeric" 

look @ ?'[' in particular, drop argument

drop: matrices , arrays.  if ‘true’ result coerced       lowest possible dimension (see examples).        works extracting elements, not replacement.  see       ‘drop’ further details. 

to answer question, want

k[order(k[,1]), , drop=false] 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -