I am trying to extract the first letter of a string that are separated by commas, then counting how many times that letter appears. So an example of a column in my data frame looks like this:
test <- data.frame("Code" = c("EKST, STFO", "EFGG", "SSGG, RRRR, RRFK",
"RRRF"))
And I'd want a column added next to it that looks like this:
test2 <- data.frame("Code" = c("EKST, STFO", "EFGG", "SSGG, RRRR, RRFK",
"RRRF"), "Code_Count" = c("E1, S1", "E1", "S1, R2", "R1"))
The code count column extracts the first letter of the string and counts how many times that letter appears in that specific cell.
I looked into using strsplit to get the first letter in the column separated by commas, but I'm not sure how to attach the count of how many times that letter appears in the cell to it.