R: How to access the elements of a list in a loop -
i have 2 files. 1 file contains information genes. looks this.
query| gene | desc apeco1_1380 | flda | flavodoxin flda apeco1_2545 | fpr |ferredoxin-nadp reductase apeco1_3632 |fldb | flavodoxin fldb apeco1_1465 |fepa | ferrienterobactin receptor apeco1_4396 | cira | colicin receptor
the second files contains list of genecodes.
apeco1_1380 apeco1_2545 apeco1_3632
i'm trying extract gene information file 1 gene codes in file 2. below code i'm using.
#files gene data genecodes(file 1) datat = read.csv("d://sbmlexploration/genes/genenames.csv",header = true) #has second type of files (files genecode) - file 2 filelist = list.files("d://sbmlexploration/genes/test1") df = data.frame(monkcode = character(), genename = character(), description = character(), stringsasfactors = f) for(i in 1:length(filelist)) { currentgenes = read.csv(filelist[i],header = t) for(j in 1:nrow(currentgenes)) { curentrow = subset(datat,datat$query == currentgenes[j,1]) df<-rbind(df,data.frame(monkcode = currentrow$query, genename = currentrow$gene, description = currentrow$desc)) } write.table(df,filename,sep=",",row.names = f) df = null }
my problem when provide gencode currentgenes[j,1]
query returns 0 rows. when give code string (with in apeco1_1465
) returns record. issue way i'm referring list. can please me this?
simply transform currentgenes[j,1]
string using as.character()
.
i.e.as.character(currentgenes[j,1])
Comments
Post a Comment