I have a function that looks like this:
removeRows <- function(dataframe, rows.remove){
dataframe <- dataframe[-rows.remove,]
print(paste("The", paste0(rows.remove, "th"), "row was removed from", "xxxxxxx"))
}
I can use the function like this to remove the 5th row from the dataframe:
removeRows(mtcars, 5)
The function output this message:
"The 5th row was removed from xxxxxxx"
How can I replace xxxxxxx with the name of the dataframe I have used, so in this case mtcars?
dataframe <- dataframe[rows.remove,]does not propagate changes outside the function call? Also,rows.removeis supposed to be negative.-rows.remove. Sorry, don't understand what you mean by 'does not propagate changes outside the function call'. This is my fault, not yours. Could you expand please?removeRowsas it stands now, R will create a copy of yourdataframeand modify the copy. When the function terminates, the (modified) copy is destroyed, and the originaldataframewill be untouched. If you want to change the original data, you must call it asmtcars <- removeRows(mtcars, 5)AND add the linedataframe(orreturn(dataframe)) at the end of the function code.