Many thanks! It work very well. At the end I would like to filter out all genes with less than 3-10 reads to conduct differential gene expression analysis. I'm aiming to rebuild 'cm' having "zeros" in the rows which total-sum<3 reads by tissue (B: brain...etc).
Dear colleagues I'm trying to create a list of data frames from an original matrix. Each new data frame should have a new column with a row-sum that will be used to subset the new data frames accordingly. The point is I'm unable to get the desired data frame structure with multiple columns, I just get one vector-like files. I will appreciate your help, thanks in advance. Roberto
cm: matrix with columns B1,B2,B3,F1,F2,F3....S1,S2,S3 and rownames gene1...16432
t=c("B","F","L","I","M","S")
cm.f=list()
for (i in 1:6)
{
a= data.frame("OoenG" = rownames(cm), cm[,grep(t[i], colnames(cm))]); cm.f[t[i]] = data.frame(apply(a[,2:4],1,sum));
cm.f[t[i]]=data.frame(a,cm.f[t[i]]);
print(summary(cm.f[[i]] <3))
}
Mode NA's logical 16432 Mode NA's logical 16432 Mode NA's .............
warnings() Warning messages: 1: In cm.f[t[i]] <- data.frame(a, cm.f[t[i]]) : number of items to replace is not a multiple of replacement length 2: In Ops.factor(cm.f[[i]], 3) : ‘<’ not meaningful for factors
just the gene names are included and the original data in "a" is not included.
1 answer
Try this for creating the list of data.frames.
t=c("B","F","L","I","M","S")
cm.f=list()
for (i in 1:6)
{
a= data.frame("OoenG" = rownames(cm), cm[,grep(t[i], colnames(cm))]);
a$mysum<-apply(a[,2:4],1,sum)
#Remove rows i which the sum is smaller than 3
a<-a[a$mysum>3,]
cm.f[[t[i]]] <- a
}
I am not sure about what is your aim with the command:
print(summary(cm.f[[i]] <3))
Can you explain?
EDIT: Added the line after the comment a<-a[a$mysum>3,]to remove all entries in which the sum is smaller than 3.
Log in to answer this question.
Can you provide a small, reproducible example?
However, it looks like you have 2 problems:
1) In a dataframe of X rows, you are trying to add a column with Y elements, where X<>Y
2) Your data.frame has values stored as factors, while you are probably using them as numeric.
Thanks Fabio, here an example of my CM matrix: