List filtration
try this:
lis. <- lapply(lis, function(x) if (length(ind <- grep("^IPI", x)))
x[ind[1]] else NULL)
lis.[!sapply(lis., is.null)]
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Johannes Graumann" <johannes_graumann at web.de>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, February 22, 2007 3:33 PM
Subject: [R] List filtration
Hello R-ologists, Imagine you have a list "list" like so:
list
[[1]] [1] "IPI00776145.1" "IPI00776187.1" [[2]] [1] "Something" "IPI00807764.1" "IPI00807887.1" [[3]] [1] "IPI00807764.1" [[4]] [1] "Somethingelse" What I need to achieve is a filtered list "list2" like so:
list2
[[1]] [1] "IPI00776145.1" [[2]] [1] "IPI00807764.1" [[3]] [1] "IPI00807764.1" So: - if sublist-entry 1 start with "^IPI" make it the list-entry. - otherwise chose the first "^IPI" sublist-entry present. - delete the list-entry if not "^IPI" sublist-entry present. Can anybody nudge me towards an elegant solution without looping - I have LOTS of entries to process ... Thanks for your Teachings, Joh
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm