Dominique Paul Dominique Paul - 1 year ago 91
R Question

R function executes without error but doesnt change column content in data frame

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)

Answer Source

Try this:

data3 = c(1,2,3,4,5)
data3 = data.frame(data3)
data3$new = c(1,1,1,1,1)
insertElementToColumn = function(x, column){
  data3$new = 2
data3 = insertElementToColumn(new, data3)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download