Trying to implement a solution to an earlier post, and have encountered behavior that I do not understand using functions.
I have a dataset of the form:
tC <- textConnection("Col1 Col2 Col3
yes no no
yes no yes
yes yes yes");
data1 <- read.table(header=TRUE, tC);
close.connection(tC);
rm(tC);
data1["Col4"] <- NA;
Now I would like to use a function to (for now) arbitrarily replace the entries in column 4:
updateRow <- function(rIndex) {
data1[rIndex, 4] <- 1
data1 <- return(data1)
}
However, when I apply the function, it seems to update as expected (entry of row 1 col4 becomes "1"), but then the dataframe reverts to its original content when I call it:
updateRow(4)
data1
Could someone explain why this is and what I am doing wrong?