vendredi 2 mars 2018

How to create a column grouping information from column with characters

I have a column in a database with this organization:

Example:

Location    
A_1
A_1
A_2
A_3
A_3
B_1
B_2

I want to group them by the first part ("A"); that is, I want to create a new column based on the letter, so the database would look like this:

Location    Location_1
A_1         A
A_1         A
A_2         A
A_3         A
A_3         A
B_1         B
B_2         B

I already tried the mutate() and ifelse() functions following another post here (Create column with grouped values based on another column), but I get this error:

"Error in UseMethod("mutate_") : no applicable method for 'mutate_' applied to an object of class "character""

Does someone know how to fix this problem or another method?

Aucun commentaire:

Enregistrer un commentaire