sorting - Change row names in R, sort by date -




this question has answer here:

i have dataframe of first column date object (used lubridate) , other columns show number of items sold. i'm having issues row names (numbers). is, row names not in order of dates:

enter image description here

i tried using rownames, can't figure out how sort row names date, july 28 becomes '2', july 29 becomes '3', etc. have way achieve this? if additional information needed, please let me know. in advance!

you can use built-in order function:

newdata <- df[order(df$date),] 

if rownames persist out of order, can reset them:

rownames(newdata) <- null 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -