dimanche 2 mai 2021

Two mixed columns in R data frame

I have a data frame with two character vectors:

data.frame(
           animal = c("blue", "dog", "yellow", "lion", "mouse"), 
           color = c("bird", "red", "cat", "green", "orange")
)

I want to have the right character in the right columns, e.g. blue is a color not a name as well as yellow:

data.frame(
           animal = c("bird", "dog", "cat", "lion", "mouse"), 
           color = c("blue", "red", "yellow", "green", "orange")
)

How should I order the data without the colors() function? Thank you for your help.

Aucun commentaire:

Enregistrer un commentaire