user4367461
user4367461

Reputation:

Trying to sort column in alphabetical order in R, not accounting for lowercase letters

I'm aware that df[order(df$name),] will sort my column alphabetically, and this does work, however it is not accounting for characters that start with a lowercase letter. i.e Apple will be sorted but apple will not.

Is there a way to solve this problem?

Upvotes: 1

Views: 2059

Answers (1)

Hack-R
Hack-R

Reputation: 23211

df[order(tolower(df$name)),]

should do the trick. tolower and toupper are generally useful whenever you have casing issues.

Upvotes: 4

Related Questions