Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print the last row from a list of data frames

Tags:

r

lapply

I have a list of data frames which I need to obtain the last row of the 2nd column from. All the data frames have differing number of rows. I've already written code using lapply which can extract any row by variable "num" (returning NA for numbers which exceed the row length of the data frames) , however I want to include a variable num="worst" which will return the last row, 2nd column of available data. This is the code to retrive the "nth" row (xyz is the list of data frames):

if(num=="best"){num=as.integer(1)} else
(num=as.integer())

rownumber<-lapply(xyz, "[", num, 2, drop=FALSE)

Been cracking my head all day trying to find a solution to declare num=="worst". I want to avoid loops hence my use of lapply, but perhaps there is no other way?

like image 808
clattenburg cake Avatar asked Oct 17 '13 17:10

clattenburg cake


1 Answers

How about...

lapply(xyz, tail, 1)
like image 188
Jilber Urbina Avatar answered Sep 21 '22 18:09

Jilber Urbina