I have over 200 data.frames in my global environment. I would like to remove the first row from each data.frame, but I am not sure how.
Any help will be appreciated please let me know if further information is needed.
I have over 200 data.frames in my global environment. I would like to remove the first row from each data.frame, but I am not sure how.
Any help will be appreciated please let me know if further information is needed.
This will list all the data frames in your environment, remove the first row from each, and organize them into a list of data frames. Generally, better practice to have them in a list so you can more easily apply
functions across them and access them.
df <- lapply(ls(), function(x) get(x)[-1,])
Update: good idea to check if objects are in fact data frames and only work with those. First we create a logical vector listing dataframes, then combine them into a list and remove the first row of each.
dfs = sapply(ls(), is.data.frame)
lapply(mget(names(dfs)[dfs]), "[", -1, , drop = FALSE)
thanks to comments for finding my error and providing more efficient solutions