0

I want to use the function gsub with sapply on a dataframe:

df_mod=as.data.frame(sapply(data_mod,gsub,pattern=data_mod$marq,replacement=""))

my problem is in the parameter pattern on the gsub function. In all the examples that I've seen, they pass a string to this parameter, like: pattern="string". For my case, I want to pass a variable as mentioned above : pattern=data_mod$marq

But I keep having these warnings that affected my results:

  Warning messages:
  1: In FUN(X[[i]], ...) :
  argument 'pattern' has length > 1 and only the first element will be used
  2: In FUN(X[[i]], ...) :
  argument 'pattern' has length > 1 and only the first element will be used
  3: In FUN(X[[i]], ...) :
  argument 'pattern' has length > 1 and only the first element will be used

Is it possible to pass a variable to pattern parameter. If so, It will give me a perfect result.

Please help me.

UPDATE

switching sapply by mapply resolved the problem :

df_mod=as.data.frame(mapply(gsub,data_mod$marq,"",data_mod$nom_det))
Jaap
  • 81,064
  • 34
  • 182
  • 193
sarah
  • 229
  • 5
  • 13

0 Answers0