I have a list of gene names in file a.File a has 1 variable and 264 observations. Another list(file b) which includes several gene names and information about these genes, file b has 10 variables and 16558 observations. I do it in R and I want to check file b for the genes in file a and I want to extract whole row an put into an empty data frame(filec) when the gene name specified in file a matches with the gene name in file b. I write something like this:
filea <- read.csv("filea.csv", sep = ";")
fileb <-read.csv("fileb.csv", sep = ";")
filec <- data.frame()
for (i in 1:dim(filea)[1]) {
for (j in 1:dim(fileb)[1]) {
if (as.character(filea[i, 1]) == as.character(fileb[j, 1])) {
filec <- merge(fileb[j, 1], filec)
}
}
}
But it gives error. What can I do? Thanks in advance.
Err, why don't you drop the
forloops? You'll also want to directly mergefileaandfileb.BTW, you might want to use the
dplyrpackage, it provides more efficient join methods (e.g.,left_join()).