[R] subsetting tables
Jannis
bt_jannis at yahoo.de
Tue Sep 6 16:35:33 CEST 2011
Sorry If I miss the point you want to achieve, but why not just:
which(red > 0.5)
or
red[which(red > 0.5)]
if you want to use this col/row wise you could do:
apply(red, 1, function(x)x[x>0.5])
and
apply(red, 1, function(x)x[x>0.5])
?
--- netzwerkerin <lehmannk at informatik.uni-tuebingen.de> schrieb am Di, 6.9.2011:
> Von: netzwerkerin <lehmannk at informatik.uni-tuebingen.de>
> Betreff: [R] subsetting tables
> An: r-help at r-project.org
> Datum: Dienstag, 6. September, 2011 14:10 Uhr
> Hi guys,
>
> one of the questions where you need a real human instead of
> a search engine,
> so it would be great if you could help.
>
> I have a matrix of z-scores which I would like to filter,
> sometimes
> columnwise, sometimes rowwise. Data looks like this:
>
> Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2
> 2 0.87
> 0.79
> -0.57 1.07
> 3 0.67 -1.14
> -0.78 -0.95
> 4 -0.46 -0.30
> -0.36
> 1.14
>
> Now I want to find all elements which are below/above some
> threshold. Subset
> works fine with the columns:
>
> > subset(red[,4], red[,4] > 0.5)
> [1] 1.07 1.14
>
> But not with the rows:
>
> > subset(red[2,], red[2,] > 0.5)
> Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2
> 3 0.67 -1.14
> -0.78 -0.95
>
> If I try to find all values above 0.5 (any row, any column,
> I just need the
> number of entries), this is what I try (and get):
>
> > subset(red[,], red[,] > 0.5)
> Allstar hsa.let.7a hsa.let.7a.1
> hsa.let.7a.2
> 2 0.87
> 0.79
> -0.57 1.07
> 3 0.67
> -1.14 -0.78
> -0.95
> NA NA
> NA
> NA
> NA
> NA.1 NA
> NA
> NA
> NA
> NA.2 NA
> NA
> NA
> NA
>
> Obviously I'm doing something wrong, but what?
> Help very much appreciated.
> Netzwerkerin
>
> --
> View this message in context: http://r.789695.n4.nabble.com/subsetting-tables-tp3793509p3793509.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list