Apply and function a gsub in a lots of columns
apply, function, gsub, multiple-columns, r
Solution
Here is another solution. It returns all the columns of the original dataframe
library(dplyr)
mutate_at(x, 6:12, gsub("\\.", "", .))
Problem
I am kind of new to R and I want to apply the `gsub` function in columns 6 to 12 in my data frame called `x`. However, I am kind of stuck. I started using: ``` gsub("\\.", "",x[,c(6:12)]) ``` But then it returned only a few rows. Then, I tried to use this: ``` x1<-apply(x,c(6:12),function(x) gsub("\\.", "",x)) ``` But I got the following error: ``` Error in if (d2 == 0L) { : missing value where TRUE/FALSE needed ``` Also tried this: ``` for (i in x[,c(6:12)]) {a<-data.frame(gsub("\\.", "",i))} ``` Does anybody have a tip or a solution? It would also be great if someone showed me how to use an `apply` function and `for`.