[R] Help, how to find the genes with A<19?

arun smartpink111 at yahoo.com
Sat May 4 19:28:42 CEST 2013


Hi,

You can get the table results in a matrix:
 Unel<-sort(unique(unlist(dat1)))
 res2<- t(mapply(function(x,y) ifelse(x %in% names(y),y[as.character(x)],0),list(Unel),lst1))
 dimnames(res2)<- list(rownames(dat1),Unel)
 head(results)
#   A M P
#1 38 0 0
#2 38 0 0
#3 38 0 0
#4 34 2 2
#5 38 0 0
#6 38 0 0
#or
 res3<-do.call(rbind,lapply(lst1,function(x) {x1<-x[match(Unel,names(x))]; x1[is.na(x1)]<-0; names(x1)<- Unel;x1 }))
head(res3)
#   A M P
#1 38 0 0
#2 38 0 0
#3 38 0 0
#4 34 2 2
#5 38 0 0
#6 38 0 0
identical(res2,res3)
#[1] TRUE
 res2Alt19<-which(res2[,"A"]<19)
 names(head(res2Alt19)) #here 38 is included because the count of "A" is zero.
#[1] "19" "38" "39" "40" "41" "42"
res3Aeq0<-which(res3[,"A"]==0)
 names(head(res3Aeq0))
#[1] "38" "42" "44" "47" "67" "89"
A.K.



----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Saturday, May 4, 2013 12:46 PM
Subject: Re: Help, how to find the genes with A<19?

Hi,

lst1<-apply(dat1,1,table)
res<-which(unlist(lapply(lst1,function(x) {indx<-names(x)%in%"A"; if(any(indx)) x[indx]<19 else NA}),use.names=FALSE))
head(res)
#[1] 19 39 40 41 43 45
 length(res)
#[1] 1481
lst1[c(19,39,40)]
#$`19`
#
# A  P 
# 1 37 
#
#$`39`
#
# A  P 
#12 26 
#
#$`40`
#
# A  P 
#16 22 
#rows without "A"
res1<-unlist(lapply(lst1,function(x) {indx<-names(x)%in%"A"; if(any(indx)) x[indx]<19 else NA}),use.names=FALSE)
 resNoA<-which(is.na(res1))
 head(resNoA)
#[1] 38 42 44 47 67 89
lst1[c(38,42)]
#$`38`
#
# P 
#38 
#
#$`42`
#
# M  P 
# 1 37 
 dat1[38,]
#   call call.1 call.2 call.3 call.4 call.5 call.6 call.7 call.8 call.9 call.10
#38    P      P      P      P      P      P      P      P      P      P       P
#   call.11 call.12 call.13 call.14 call.15 call.16 call.17 call.18 call.19
#38       P       P       P       P       P       P       P       P       P
#   call.20 call.21 call.22 call.23 call.24 call.25 call.26 call.27 call.28
#38       P       P       P       P       P       P       P       P       P
#   call.29 call.30 call.31 call.32 call.33 call.34 call.35 call.36 call.37
#38       P       P       P       P       P       P       P       P       P


A.K.

>Thank you for your help 
>
>But what I mean is that, for example, in row 1 (gene1),  dat1[1,], there are 38 As in this row. 
>What I want to find is in these 7129 rows, in how many (which) rows, that there are no more than 18 As within one row. 
>Or should I say, the count for the character "A" is no more than 18 in one row. 
>
>Thanks 


----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Saturday, May 4, 2013 11:43 AM
Subject: Re: Help, how to find the genes with A<19?



Hi,
If it is to get the first 18 genes (based on rownumbers)
dat1<- read.table("apcall.txt",header=TRUE,sep="",stringsAsFactors=FALSE)
 dat1[1:18,]

#or
dat1[as.numeric(rownames(dat1))<19,]
A.K.



>The row numbers represent 7129 different genes 
>The 38 columns represent 38 different patients 
>How can I find the genes with A number < 19 in these 7129 genes? 
>I have searched and tried for 7 hours but still can not find the way to solve 
apcall.txt



More information about the R-help mailing list