いくつかの NA 値を含むデータに適合する lm() の勾配を平均化するカスタム関数で dlply() を使用しています。 = singular.ok, ...) : 0 (非 NA) ケース"
このエラーは、2 つのキー変数を使用して dlply を呼び出した場合にのみ発生します。1 つの変数で区切ると問題なく動作します。
厄介なことに、単純なデータセットではエラーを再現できないため、問題のデータセットをドロップボックスに投稿しました。
エラーを生成しながら可能な限り最小化されたコードを次に示します。
masterData <- read.csv("http://dl.dropbox.com/u/48901983/SOquestionData.csv", na.strings="#N/A")
workingData <- data.frame(sample = masterData$sample,
substrate = masterData$substrate,
el1 = masterData$elapsedHr1,
F1 = masterData$r1 - masterData$rK)
#This function is trivial as written; in reality it takes the average of many slopes
meanSlope <- function(df) {
lm1 <- lm(df$F1 ~ df$el1, na.action=na.omit) #changing to na.exclude doesn't help
slope1 <- lm1$coefficients[2]
meanSlope <- mean(c(slope1))
}
lsGOOD <- dlply(workingData, .(sample), meanSlope) #works fine
lsBAD <- dlply(workingData, .(sample, substrate), meanSlope) #throws error
洞察をお寄せいただきありがとうございます。