I need to create a variable using assign()
to give it a dynamic name.
I later need to remove the variable.
day_no <- 1
df <- data.frame( a = 1:3, b = 4:6 )
assign( paste0( 'newdf_' ,day_no ), df )
This works fine.
The trouble is removing the variable afterwards. I have tried:
rm( paste0( 'newdf_', day_no ) )
Or:
rm( parse( paste0( 'newdf_', day_no ) ) )
However I get this error message:
Error in rm(parse(paste0("newdf_", day_no))) :
... must contain names or character strings
I have searched a lot online but cannot find the answer, some help would be much appreciated.
For non-interactive use, use the list
argument to pass your character name(s).
rm(list = paste0("newdf_", day_no))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With