What is the most efficient way to apply gsub to various columns?
The following does not work
x1=c(\"10%\",\"20%\",\"30%\")
x2=c(\"60%\",\"50%\",
The first answer works but be careful if you are using data.frame with string: the @docendo discimus's answer will return NAs.
If you want to keep the content of your column as string just remove the as.numeric and convert your table into a data frame after :
as.data.frame(apply(x, 2, function(y) as.numeric(gsub("%", "", y))))
x1 x2 x3
[1,] 10 60 1
[2,] 20 50 2
[3,] 30 40 3