I am trying to combine multiple actions in one ifelse-statement. The second actions is working with the first one and so on, but I get the error warning: "operations are possible only for numeric, logical or complex types".

The error refers to data I produced before, and it is a working directory, saved as character. Therefore I can not change it to numeric, logical or complex. I tried it, but it becomes NA.

Using as.factor results in the same error warning. When I run the code step by step there is no error, it occurs only if I run the whole ifelse-statement.

The problem occurs in the line of the ifelse-statement "meta_nam <- paste(folders, ".xlsx", sep="")"

I think the "folders" is the problem. The data looks like: "O:/data/Projekt/a"

 condition1 <- as.Date(sub(".*/(.*)","\\1",x), "%Y.%m.%d")>as.Date("2017-03-05")
 ifelse(condition1==T, yes=((meta_nam <- paste(folders, ".xlsx", sep="")) &
                              (exist <- file.exists(meta_nam)) &
                              (for (i in 1:length(folders)) {
                                if(exist[i]==F) 
                              {stop(paste("Meta-Excel fehlt fuer: ", folders[i]))}}) &
                              (me=lapply(meta_nam, function(y) read_excel(y))) &
                              (me=lapply(me, function(y) as.data.frame(y[!is.na(y$dID), 
                               seq(which(colnames(y)=="dID"), which(colnames(y)=="parameter_stop")-1)]))) &
                              (me=lapply(me, function(y) y[,colSums(is.na(y))<nrow(y)])) &
                              (me=lapply(me, function(y) y[rowSums(is.na(y))<(ncol(y)-1),])))

        , no=((meta_nam=paste(folders, ".csv", sep="")) &
                (exist=file.exists(meta_nam)) & 
                (for (i in 1:length(folders)) {
                  if(exist[i]==F) 
                  {stop(paste("Meta-Excel fehlt fuer: ", folders[i]))}}) &
                (me=lapply(meta_nam, function(y) read.table(y, sep="\t", header=T, stringsAsFactors=F))) &
                (me=lapply(me, function(y) y[,colSums(is.na(y))<nrow(y)])) &
                (me=lapply(me, function(y) y[rowSums(is.na(y))<(ncol(y)-1),]))))

The idea behind using an ifelse-statement is to reduce the runningtime, before I used an if... else... argument, there was no problem.

0 Answers