0

I'm trying to create a function that takes for parameter a dataframe, but –even if it doesn't return errors–, it doesn't seem to be doing any changes on my data either.

The script I used was:

 func <– function(x) {
   
   for (i in seq(from=1, to=dim(x)[1], by=1)){

    if (grepl("econom",x$var1[i],ignore.case=TRUE)==T) {

      x$var2[i]="E"
    }
  }
    
  }

What it should do is to assign value "E" to a variable named var2 if var1 contains the string "econom".

Can anybody see what I'm missing?

Thanks!

  • What are you trying to do? refer https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example to ask a reproducible example – Nad Pat Dec 09 '21 at 13:00

0 Answers0