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"), using R; 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?
Here is part of the .csv file I am using:
Location Species Time
A_1 FC 0.52
A_1 JC 0.64
A_2 JC 0.31
A_2 FC 0.02
A_2 FC 0.01
A_3 FC 0.13
A_3 JC 0.97
A_3 OT 0.86
A_3 JC 0.55
B_1 JC 0.32
B_1 OT 0.04
B_1 OT 0.06
B_2 OT 0.12
B_2 JC 0.13
B_2 JC 0.14
B_2 OT 0.56
C_1 OT 0.57
C_1 OT 0.86
C_1 FC 0.58
C_1 FC 0.76
... ... ...