[R] Manipulating lists

From: Christian Arnold <chrarnold_at_web.de>
Date: Sun, 16 Nov 2008 22:56:35 -0500

Hello R-Community,

I am pretty new to R and I am fascinated what R can do! I am doing phylogenetic analysis in R, and my current project includes two problems that I am unable to solve, unfortunately. I am hoping that someone knows an easy, and R-typical solution, any help would be appreciated. Specifically, I have the following two problems:

  1. I am reading in all the files from a directory using file_list <- list.files(). It works, of course, however, I want to restrict file_list to files that end with ".nex". Thus, I want to remove some files from this list. I read that I can do something like file_list <- file_list[condition]. I do not know how to express my condition here, unfortunately. Pseudo code would be something like file_list <- file_list[ends with ".nex"]
  2. A slightly more complicated problem, at least I think that. I have two lists, list1 and list2. list1 contains some elements (characters such as "species1"). list2 contains also species names, including all of list1, but also species that are not part of list1. I need a way to create a list that contains ONLY those elements that are in list2, but not in list1. For example: list1 = c("s1","s3","s4","s7"), list2 = c("s1","s2","s3","s4","s5","s6","s7"), now I need a way to create the list list3 = c("s2","s5","s6"). Any ideas? I am not able to find the appropriate function...


R-help_at_r-project.org 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. Received on Mon 17 Nov 2008 - 04:00:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Nov 2008 - 05:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive