我有一個SQL表通過dplyr設置是這樣的:在dplyr mutate中使用自定義函數?
num gameday_link stand b_height px pz type
1 1 gid_2016_04_05_houmlb_nyamlb_1 R 5-6 0.194 3.225 B
2 1 gid_2016_04_05_houmlb_nyamlb_1 R 5-6 0.510 1.965 S
3 1 gid_2016_04_05_houmlb_nyamlb_1 R 5-6 -1.367 2.459 B
我想要做的就是添加一個名爲正確的附加列,其中包含稱爲isCallCorrectV的自定義功能在T或F結果。 isCallCorrectV的參數是表中的列。
這裏是isCallCorrectV的例子在行動:
> isCallCorrectV(c(0.0, 2.5), c(2.5, 0), c("S", "B"), c("6-0", "5-0"), c("R", "L"))
[1] TRUE FALSE
我嘗試使用這個命令,但我得到一個錯誤。
dplyr::mutate(noswings, correct = isCallCorrectV(px, pz, type, b_height, stand))
Error in sqliteSendQuery(conn, statement) :
error in statement: no such function: ISCALLCORRECTV
提供用於功能代碼和R中不那拼寫是大小寫敏感的。 –
這聽起來像你是在使用SQLite後端?這不適用於用R編寫的自定義函數。如果你看[dplyr在數據庫上的小插曲](https://cran.r-project.org/web/packages/dplyr/vignettes/databases.html),你可以找到'dplyr'知道如何轉換成SQL的R函數的列表(並且'isCallCorrect'不在該列表中)。 – Gregor
@ 42-添加的定義 – zkello