0

How can cause the row_to_keep command to work with the variable b instead of using the real variable name. Thanks for your help

    > names(newdata)
    [1] "Jahr"      "Forstzone" "value,,"  
    > variablennameliste<-list("Year","year","Jahr","jahr")
    > b<-toString(intersect(names(newdata),variablennameliste))
    > print(b)
    [1] "Jahr"
    >row_to_keep = which(newdata$b!=2014)
    Warning message:
    Unknown column 'b' 

I have tried the

    assign()      

command, but it didn't work

  • @Henrik I don't this is a dupe of that question bcz of the OP's code have some elements that don't sync well or answered in that dupe – akrun Feb 10 '17 at 08:25

1 Answers1

0

We need to use [ to extract the value in the object 'b'

which(newdata[,b]!=2014)

The toString wrapper is not needed as it will convert to a single string separated by the delimiter , when there are multiple intersecting elements. In the example, there is only a single element.

b <- intersect(names(newdata),variablennameliste)

Even when there are multiple intersecting elements, the above should work as we are selecting the 'newdata' columns based on the 'b' vector. In that case, the comparison !=2014 depends on what values the columns have and the objective

akrun
  • 874,273
  • 37
  • 540
  • 662