I have been trying to create a function which will permanently change a value in specific cells of my data frame. I insert the data frame name, row index I wish to change, and the new name as a string. However, the function seems to change the value name within the local environment but not global.
The function is as follows:
#change name function
name_change <- function(df, row, name) {
df[row, 1] = name
return(df[row, 1])
}
E.g. if data frame was:
Name | Column B |
---|---|
Mark | 2 |
Beth | 4 |
The function name_change(df, 2, 'Jess') would change Beth to Jess.
When inserted as raw code it does permanently change the value. But then does not work when used as a function.
df[2, 1] = 'Jess'
Thanks in advance for your time