df99 <- structure(list(Yta = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), name = c("Lettland", "Lettland",
"Lettland", "Lettland", "Lettland", "Lettland", "Lettland", "Lettland",
"Lettland", "Lettland", "Lettland", "Lettland", "Lettland", "Lettland",
"Lettland", "Lettland", "Lettland", "Lettland", "Lettland", "Lettland",
"Lettland", "Lettland", "Lettland", "Lettland", "Lettland", "Lettland",
"Lettland", "Lettland", "Lettland", "Lettland", "Lettland", "Lettland",
"Lettland", "Lettland", "Lettland"), H99 = c(92L, 87L, 88L, 89L,
98L, 88L, 88L, 87L, 85L, 93L, 87L, 83L, 92L, 89L, 94L, 98L, 93L,
97L, 93L, 88L, 94L, 93L, 98L, 95L, 91L, 95L, 96L, 91L, 93L, 92L,
91L, 84L, 87L, 96L, 94L), D99 = c(75L, 72L, 75L, 80L, 79L, 82L,
78L, 75L, 62L, 83L, 70L, 81L, 80L, 89L, 88L, 95L, 86L, 76L, 76L,
67L, 81L, 85L, 91L, 85L, 69L, 67L, 85L, 79L, 80L, 79L, 83L, 58L,
56L, 111L, 74L)), class = "data.frame", row.names = c(NA, -35L
), .Names = c("Yta", "name", "H99", "D99"))
Я пытаюсь написать функцию, которая включает dplyr
пакет
calcCoef <- function(dff, h, d){
quo_h <- enquo(h)
quo_d <- enquo(d)
dff %>% group_by(Yta) %>% filter(!! quo_d > 0) %>%
do(tidy(nls(!! quo_h ~ !! quo_d^2 / (a + b * !! quo_d)^2 + 1.3, start = c(a = 0.1, b = 0.1), data = dff))) %>%
select(Yta, term, estimate) %>% dcast(., Yta~term )
}
calcCoef(df99, h = H99, d = D99)
Но что-то идет не так
Ошибка в quo_d ^ 2: не числовой аргументна бинарный оператор