[R] Lists of tables and conditional statements

Henrique Dallazuanna wwwhsd at gmail.com
Thu Mar 31 02:27:31 CEST 2011


Try this:

 lapply(l, function(x)x[x[,'Sum'] == 3,])

On Wed, Mar 30, 2011 at 7:38 PM, Herbert, Alan G <aherbert at bu.edu> wrote:
> Hi R-users,
>
> I have a list containing numeric tables of differing row length. I want to make a new list that contains only rows from tables with a "Sum" greater than 3, plus the names of each table. I was wondering whether there is an elegant way to do this using apply of related functions as this list has many thousands of such tables.
>
> Here is an example of the list
>
>
> $AACS
>
>                        POOL
>
> INFO                     pool1 pool2 pool6 pool7 pool8 pool.all Sum
>
>  12:125561133:novel         0     0     0     0     1        0   1
>
>  12:125570904:novel         0     0     0     0     1        0   1
>
>  12:125571014:novel         0     1     0     0     0        0   1
>
>  12:125571038:novel         0     0     0     1     0        0   1
>
>  12:125575996:novel         0     0     0     1     0        0   1
>
>  12:125591844:rs2297478     1     0     1     0     0        1   3
>
>  12:125599114:novel         0     0     0     1     0        0   1
>
>  12:125612668:novel         0     0     0     0     1        0   1
>
>  12:125612839:rs900411      1     0     1     0     1        1   4
>
>  12:125626650:novel         0     0     0     0     1        0   1
>
>  12:125626737:novel         0     0     0     1     0        0   1
>
>
>
> $AADAC
>
>                        POOL
>
> INFO                     pool1 pool2 pool5 pool6 pool7 pool8 pool.all Sum
>
>  3:151542411:novel          0     0     0     0     1     0        1   2
>
>  3:151542412:novel          0     0     0     0     1     0        1   2
>
>  3:151542643:novel          0     1     0     0     0     0        0   1
>
>  3:151545322:rs2410836      0     1     0     0     0     0        1   2
>
>  3:151545323:rs62272918     0     1     0     0     0     0        1   2
>
>  3:151545509:novel          0     0     1     0     0     0        1   2
>
>  3:151545601:rs1803155      1     1     1     1     1     1        1   7
>
>  3:151545721:novel          0     0     1     0     0     0        0   1
>
>  3:151545802:novel          0     0     0     0     1     0        0   1
>
>  3:151545824:novel          0     1     0     0     0     0        0   1
>
>
> Thanks for your help
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list