Hi everyone I have this main dataframe with two cols" Ac" and "description" and several other excel files that are my samples with the same col headers "Ac and "description". I wish to check if the rows of each sample file exists in the main dataframe with a conditional output (TRUE,FALSE). and i will combine each sample output with the main dataframe; therefore my goal is something like this: - AcDes Sample1 Sample2 - UniprotP6666 ProteinA True False - Uniprot P7777 ProteinB False True
i have 29 samples and i am looking for a smart way to do this instead of typing this 29 times sample1match<-ifelse(maindf$Ac%in%sample1.xls$Ac,"True","False") and combinining all of e.g. sample1match into a single df
i tried this:
temp = list.files(pattern="*.xls") for (i in 1:length(temp)) assign(temp[i], read_xlsx(temp[i]))
temp is a list of dfs in which each element is my sample excel file. for (i in 1:length(temp)) {ifelse(maindf["Accesssion"] %in%i["Accession"],"TRUE","FALSE")} maindf is the uniqueaggregatedaccesssion ; ```Error in [.data.frame(uniqueaggregatedaccession, "Accesssion") : undefined columns selected 5. stop("undefined columns selected") 4. [.data.frame(uniqueaggregatedaccession, "Accesssion") 3. uniqueaggregatedaccession["Accesssion"] 2. uniqueaggregatedaccession["Accesssion"] %in% i["Accession"] 1. ifelse(uniqueaggregatedaccession["Accesssion"] %in% i["Accession"], "TRUE", "FALSE")
also tried using lapply `lapply(temp,function(x)`
``` ifelse(uniqueaggregatedaccession$Accession%in%temp(x),"TRUE"","FALSE") Error: unexpected string constant in " lapply(temp,function(x) ifelse(uniqueaggregatedaccession$Accession%in%temp(x),"TRUE"","FALSE"
quite a newbie at this and Will appreciate any advise where my code gone wrong. thanks!
Aucun commentaire:
Enregistrer un commentaire