I have a nice list that looks like this:
tmp = NULL
t = NULL
tmp$resultitem$count = "1057230"
tmp$resultitem$status = "Ok"
tmp$resultitem$menu = "PubMed"
tmp$resultitem$dbname = "pubmed"
t$resultitem$count = "305215"
t$resultitem$status = "Ok"
t$resultitem$menu = "PMC"
t$resultitem$dbname = "pmc"
tmp = c(tmp, t)
t = NULL
t$resultitem$count = "1"
t$resultitem$status = "Ok"
t$resultitem$menu = "Journals"
t$resultitem$dbname = "journals"
tmp = c(tmp, t)
What produces:
> str(tmp)
List of 3
$ resultitem:List of 4
..$ count : chr "1057230"
..$ status: chr "Ok"
..$ menu : chr "PubMed"
..$ dbname: chr "pubmed"
$ resultitem:List of 4
..$ count : chr "305215"
..$ status: chr "Ok"
..$ menu : chr "PMC"
..$ dbname: chr "pmc"
$ resultitem:List of 4
..$ count : chr "1"
..$ status: chr "Ok"
..$ menu : chr "Journals"
..$ dbname: chr "journals"
Now I want to search for each item resultitem. I want to know dbnamefor every database that has less than 10 count(example). In this case, it is very simple, since this list contains only 3 elements, but the real list is a little longer.
This can be done simply with a for loop. But is there a way to do this with some other R function (e.g. rapply)? My problem with these applicable functions is that they only look at one element.
If I do grep to get all the elements dbname, I cannot get the count of each element.
rapply(tmp, function(x) paste("Content: ", x))[grep("dbname", names(rapply(tmp, c)))]
Does anyone have a better idea than a for loop?