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 combining 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")
I 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"
I'm quite a newbie at this and would appreciate any advice where my code has gone wrong. Thanks!