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!