Reputation: 1
I have a list containing several data frames. I would like to delete the last row of each data frame in the list. I used
sapply(list.name,function(d){d<- d[-nrow(d),]})
but it does not work. Does anyone know how I can do this.
Upvotes: 0
Views: 293
Reputation: 18437
You were close, no need for assignement inside your function.
newlist <- lapply(dflist, function(d) d[-nrow(d), ])
This is a more general solution that you can adapt to other problems but in this case @textb solution more efficient.
Upvotes: 1