0

I would like to write functions for my very long code. Unfortunately I cant include variables into my functions.

Example:

class.function <- function(var2){
  
df$var2 <- as.numeric(df$var2)

}

My problem is. The as.numeric function sees "var2" as a part of the dataframe and not as my variable which should be assigned by my function.

I tried it with different combinations of [],() and "", but it was more trying than knowing.

akrun
  • 874,273
  • 37
  • 540
  • 662
bluelagune
  • 13
  • 2
  • bluelagune, the dupe link augments akrun's correct recommendation for resolving your issue. If for some reason neither this answer nor the linked answer(s) truly resolve your issue, @-ping me and we'll work through the differences. If it is resolved, you can still accept akrun's answer if you choose to (and I encourage it): the "closed" status just means that we cannot post new answers on this, it does not restrict your ability to upvote and/or accept preexisting answers. – r2evans Mar 05 '23 at 19:31

0 Answers0