0

Greeting,

I am currently trying to set up a function to add a column to a dataframe if it doesn't already exists. Let's say columns is a vector of names I want in my dataframe. Here is what I have so far... For some reasons it adds an "i" column and that's it. I think the problem should come from the definition of i in the function, but I've tried several changes and that's still not working. Any clue ? Thanks a lot!

add_columns <- function(x){
'%!in%' <- function(u,v)!('%in%'(u,v))
for(i in columns){
if(i %!in% colnames(x)) {
  x$"i" <-100
  return(x)
  }
 }
}

0 Answers0