This is an elementary question, but I have been stuck on it for quite some time. I'm trying to group the values in ColumnB but only within each value in ColumnA.
The initial data frame would be something like:
ColumnA = c(1,1,1,2,2,2)
ColumnB = c("f","g","g","f","f","h")
df <- data.frame(ColumnA,ColumnB)
ColumnA ColumnB
1 f
1 g
1 g
2 f
2 f
2 h
The result would be:
ColumnA ColumnB
1 f
1 g
2 f
2 h
(One of the methods I tried using was with dplyr
using: group_by(df, ColumnB)
, but that attempt was unsuccessful.)