I have a list of lists like the input example below “testccffilt”. I’m trying to return a list where I pick off the name from each list and the lag. For example, for the first list it would be:
c(‘TimeToShip’,1)
I’ve tried the lapply example below, but it doesn’t give me exactly the output I’m looking for. I have an example of the desired type of output I’m trying to get also below. Any tips are very much appreciated.
input:
> testccffilt
$TimeToShip
cor lag
3284 0.9998749 1
$TimeToRelease
cor lag
3285 0.9997293 2
tried:
testlist<-lapply(testccffilt,function(x)list(names(x),x$lag))
testlist
$TimeToShip
$TimeToShip[[1]]
[1] "cor" "lag"
$TimeToShip[[2]]
[1] 1
$TimeToRelease
$TimeToRelease[[1]]
[1] "cor" "lag"
$TimeToRelease[[2]]
[1] 2
desired output:
[[1]]
[1] "TimeToShip" "1"
[[2]]
[1] "TimeToRelease" "2"
Data:
dput(testccffilt)
structure(list(TimeToShip = structure(list(cor = 0.999874880882358,
lag = 1), .Names = c("cor", "lag"), row.names = 3284L, class = "data.frame"),
TimeToRelease = structure(list(cor = 0.999729343078789, lag = 2), .Names = c("cor",
"lag"), row.names = 3285L, class = "data.frame")), .Names = c("TimeToShip",
"TimeToRelease"))