excuse me, I could not figure out here what are the
data1, genes and data2
may you please tell me based on my example above?
thank you
Hi,
I have two lists of genes
mycounts <- read.csv("geneID and length.csv", header = T, sep = "\t", stringsAsFactors = FALSE)
> colnames(mycounts)
[1] "genesID.geneslength"
> head(mycounts[1:4,])
[1] "R0010W,1272" "R0020C,1122" "R0030W,546" "R0040C,891"
> dim(mycounts)
[1] 7130 1
mycounts1 <- read.table("read.txt", header = T, sep = "\t", stringsAsFactors = FALSE)
> dim(mycounts1)
[1] 5961 1
> colnames(mycounts1)
[1] "Freq"
How I can have only genes in my read file in my genes file? I mean genes file has 7130 that I only need 5961 of them
May you help me please? Thank you
See %in% operator, e.g.:
data1_subset <- data1[ data1$genes %in% data2$genes, ]
Or we can use merge, e.g.:
data1_merge <- merge(data1, data2, by = "gene")
excuse me, I could not figure out here what are the
data1, genes and data2
may you please tell me based on my example above?
thank you
Something is weird here, since you have the names files joined with its length and separated by a comma. Am I right?. I believe that since you have only 1 column as I can see from the dim(). It is likely that you need to do the read.csv in a different way to be able to separate both values, like using a different sep value. I need to know the format of the original file to suggest you
In that case none of these suggestions will work because the genes name are common, but then the length value has to be the same to do a merge
If columns names (for merging) are different in two files
Common <- merge(mycounts, mycounts1, by.x=c("colNameFrom-mycounts"), by.y=c("colNameFrom-mycounts1"))
If columns names (for merging) are same in two files
Common <- merge(mycounts, mycounts1, by="colName")
Log in to answer this question.
Antonio is right, you are using read.csv on a comma separated file, but then set
sep = "\t".That's just wrong.