[R] subsetting tables

netzwerkerin lehmannk at informatik.uni-tuebingen.de
Tue Sep 6 22:42:03 CEST 2011


Hi Eik,

greetings to Hamburg! :-) Thanks for the fast and helpful answer


Eik Vettorazzi-2 wrote:
> 
> #compare
> str(red[,2])
> str(red[2,])
> 

I understand that the first is a real vector of nums in R and the second is
a ?? matrix/list/data.frame ?? of single ? entries? Can I
transpose/transform it into one vector? Tried 'as.vector' but did not help.


Eik Vettorazzi-2 wrote:
> 
> sum(red>.5)
> length(which(red>.5))
> 

Sorry for being unprecise. Yes, in this case it was mainly the sum (thanks!
helpful function!), but in general I'd like to understand what happened with
subset here... 


Eik Vettorazzi-2 wrote:
> 
> 
> and the arr.ind option of which may be useful as well.
> 

Thanks a lot, very helpful. For other newbies, here is the line:

 tableReduced[,-1][which(tableReduced[,-1]>0.5, arr.ind=TRUE)]

I needed to exclude the first column (-1) since these were titles (factors)
of my rows. In the first trial I forgot to add this information to the first
notion of the table as well, i.e., I tried: 

 tableReduced[which(tableReduced[,-1]>0.5, arr.ind=TRUE)]

This will (of course, I have to admit) result in subsetting fields that are
in one column to the left of the intended column. So, if there are any
subsetting indices in the which-function, they also need to be put in front
of it to make the indices match.

Just for my understanding, do you know what R did with here? Where do the NA
values come from, what is the row-title NA.1, why does it print the first
two rows unchanged and then goes crazy?

> 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 

Thanks for this community with fast and reliable help. Amazing to see!


--
View this message in context: http://r.789695.n4.nabble.com/subsetting-tables-tp3793509p3794527.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list