aggregate methods treat missing values (NA) differently

Good question, but in my opinion, this shouldn’t have caused a major debugging headache because it is documented quite clearly in multiple places in the manual page for aggregate. First, in the usage section: ## S3 method for class ‘formula’ aggregate(formula, data, FUN, …, subset, na.action = na.omit) Later, in the description: na.action: a function … Read more

Subsetting R data frame results in mysterious NA rows

Wrap the condition in which: df[which(df$number1 < df$number2), ] How it works: It returns the row numbers where the condition matches (where the condition is TRUE) and subsets the data frame on those rows accordingly. Say that: which(df$number1 < df$number2) returns row numbers 1, 2, 3, 4 and 5. As such, writing: df[which(df$number1 < df$number2), … Read more