I am trying to obtain the number of cells that are expressing the genes of interest(the gene names are stored in the data frame 'fibmatch') or control (Osr1) in each cluster using a for loop. I want to create a data frame with the frequency of each gene in each cluster. However, the for loop I have created is only saving the last iteration. Could someone give me suggestions on how to fix this? Thanks!
df = data.frame()
for (i in 1:nrow(fibmatch)){
obj <- subset(x = adult, subset = fibmatch[i,1] > 0 | Osr1 > 0)
obj <- obj@meta.data[["seurat_clusters"]]
obj <- table(obj)
df <- rbind(df,obj)
}
By creating an empty data frame and using rbind, I was attempting to save each iteration but it only saved the last iteration.