Reputation: 615
How to count values in a multiset? I have a dataset and i want to write a function for a frequency table. So that i now which abnormalities are present in my data. The data is an array and looks like this:
GSM288217 GSM288219 GSM288221
ch1_500001 NA NA NA
ch1_1500001 "Imbalance" "Balance" "Balance"
ch1_2500001 "Imbalance" "Balance" "Balance"
ch1_3500001 "Imbalance" "LOH" "Balance"
ch1_4500001 "Imbalance" "LOH" "Balance"
ch1_5500001 "Imbalance" "LOH" "Balance"
ch1_6500001 "Imbalance" "LOH" "Balance"
ch1_7500001 "Imbalance" "LOH" "Balance"
ch1_8500001 "Imbalance" "LOH" "Balance"
ch1_9500001 "Imbalance" "LOH" "Balance"
ch1_10500001 "Imbalance" "LOH" "Balance"
ch1_11500001 "Imbalance" "LOH" "Balance"
ch1_12500001 "Imbalance" "LOH" "Balance"
ch1_13500001 "Imbalance" "LOH" "Balance"
ch1_14500001 "Imbalance" "LOH" "Balance"
ch1_15500001 "Imbalance" "LOH" "Balance"
ch1_16500001 "Imbalance" "LOH" "Balance"
ch1_17500001 "Imbalance" "LOH" "Balance"
ch1_18500001 "Imbalance" "LOH" "Balance"
ch1_19500001 "Imbalance" "LOH" "Balance"
Now i want the function to check per ROW how much a certain abnormality is present in the data. I started with:
detection<- function(abnormality) {
freqcount<-rep(0,nrow(abnormality))
if(assayDataElement(abnormality, 1)=="LOH")#TRUE & FALSE?? Need frequency
{freqcount<-freqcount+1
}
return(freqcount)
}
So every time there is LOH present on the rows of the data it should give the numbers of LOH present in that row.
Upvotes: 0
Views: 1038
Reputation: 2366
I guess you need
length(which(assayDataElement(abnormality, 1)=="LOH"))
or for each row individually:
count <- function(x,what) length(which(x==what));
apply(assayDataElement(abnormality, 1),1,count,"LOH");
Upvotes: 3