Paulo
Paulo

Reputation: 11

Arranging by number of characters in variable

I would like to arrange a variable called "Name" by the number of characters in their Name. I'm aware that I need the arrange() function in the package dplyr, but do not find a function in the arrange() function that helps me to arrange based on numbers of characters in the name.

So far I have come up with: arrange((Name))

Is there someone who can help me with this?

Upvotes: 0

Views: 349

Answers (1)

atsyplenkov
atsyplenkov

Reputation: 1304

Here's a simple workaround with dplyr package and iris data:

library(dplyr)

iris %>% 
  mutate(Species = as.character(Species)) %>% # Convert factor to characters
  arrange(nchar(Species))

Upvotes: 1

Related Questions