Reputation: 35
I know how to remove the first column from each element in a list in R, but how do I remove the first row?
ldf1<-lapply(ldf, "[", -1)
Upvotes: 2
Views: 1159
Reputation: 887048
We can use map
library(purrr)
library(dplyr)
ldf1 <- map(ldf, ~ .x %>%
slice(-1))
Upvotes: 1
Reputation: 206197
You can do
ldf1 <- lapply(ldf, tail, -1)
Using tail()
with a negative number will remove that many rows from the top of the data.frame.
But you could also pass an empty parameter to lapply
lapply(ldf, `[`, -1, )
or use an anonymous function
lapply(ldf, function(x) x[-1, ])
Upvotes: 3