I am encountering something really strange.
I have a data frame called stand. I also have standards=1:2. If the number of rows of stand is less than or equal to 8, I just want to output 2:3, which should be standards+1. If it is greater than 8, I would like all of the columns being specified by the standards argument, except for the last one plus one. The standards vector refers to column labels that are offset by one from where they sit in the source data frame, hence the +1 alteration. Here is where it gets weird.
Here is exactly what I have entered
stand<-structure(list(Stand.Conc = c(5000, 2500, 1250, 625, 312.5, 0
)), .Names = "Stand.Conc", row.names = c(NA, -6L), class = "data.frame")
standards<-1:2
> nrow(stand)
[1] 6
> nrow(stand)>8
[1] FALSE
> 1+standards[1:(length(standards)-1)]
[1] 2
> standards+1
[1] 2 3
> ifelse(nrow(stand)>8,1+standards[1:(length(standards)-1)],standards+1)
[1] 2
> if(nrow(stand)>8){
+ 1+standards[1:(length(standards)-1)]}else{
+ standards+1
+ }
[1] 2 3
Somebody please help me understand what is going on here since ifelse and if else are returning two different things. if then else is working right, but ifelse seems to be returning the TRUE value even if FALSE is the result of the test. I am using R 3.2.1 GUI 1.66 Mavericks build (6956) on a MAC version 10.10.4