I have a dataframe with a list of strings in it
df$a
=========
"4343-2"
"7889-5"
"4-3456"
"334-45"
"8765-4"
I’d like to perform a string operation on the list to remove the dash sign, so I did this..
df$a <- lapply(df$a, sub, "-","", df$a)
..which only produces a set of completely empty strings. What did I get wrong?
you can just use
subdirectly.Instead of the convoluted
lapplyyou’re doing since sub is “vectorized”. You can also usegsubif you think there may be more than one dash per entry.