Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to sort/order by a specific column using the write.csv() function?

Is it possible to dynamically sort my data by a specific column on-the-fly, during the export (write.csv()) function itself?

I export my data thus:

write.csv(level_names, "level_names.csv")

But want to know if it possible to achieve something like this:

write.csv(level_names, "level_names.csv", order(dataset$longname))

I know this doesn't work - this is merely for illustration purposes.

Is something to this effect possible?

like image 854
Mus Avatar asked Jan 01 '26 02:01

Mus


1 Answers

It's not necessarily contained within that function, but you could easily do something like this using dplyr:

level_names %>% arrange(longname) %>% write_csv("level_names.csv")
like image 164
skhan8 Avatar answered Jan 03 '26 15:01

skhan8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!