0

data3 is a data frame with a column called new of which all elements are 1. The function should change all values of the column new to 2. When executing the code there is no error but the value of the column "new" is still 1.

When only executing data3$new = 2 everything works

insertElementToColumn = function(){
  data3$new = 2
}
insertElementToColumn(new, data3)
Dominique Paul
  • 1,623
  • 2
  • 18
  • 31

1 Answers1

-1

I think you should sth like this do for a general function:

insertElementToColumn = function(nameOfColumn, nameOfDF, value){
 nameOfDF[,nameOfColumn]=value
 nameOfDF[,nameOfColumn]
}
data3$new<-insertElementToColumn("new", data3, 2)
kwicher
  • 2,092
  • 1
  • 19
  • 28