0
複数のロング/ラットペアでwalkscoreAPIを使用してウォーキングスコアを計算しようとしています。ただし、関数getWS onはデータフレームの最初の入力を受け取ります。walkscoreAPI:1番目の要素のみを受け入れるデータフレーム上での使用関数
getWSは、以下のようにリスト製品を生成します。
$status
[1] 1
$walkscore
[1] 0
$description
[1] "Car-Dependent"
$updated
[1] "2017-06-08 22:49:20.313160"
$snappedLong
[1] 38.943
$snappedLat
[1] -77.076
これを念頭に置いて、リストから$ walkscoreを抽出する独自の関数を作成しようとしました。
walkscore <- function(x, y){
walk <- getWS(x, y, "YOUR API KEY")
walk$walkscore
}
これを単純な突然変異計算に使用しようとしました。
library(walkscoreAPI)
library(tidyverse)
# Create sample df
lat <- c(38.942523, 37.942523)
long <- c(-77.076403, -78.076403)
df <- tibble(
long,
lat)
#Calculate score
df1 <- df %>%
mutate(score = walkscore(long, lat))
これは
Error: invalid 'description' argument
In addition: Warning message:
In if (file == "") file <- stdin() else { :
the condition has length > 1 and only the first element will be used
どのように私は、全体のDF用getWSを実行するために、これを書き換えると、各行のための$ walkscoreを引くことができ、次のエラーがスローされますか?
[この質問](https://stackoverflow.com/questions/3505701/r-grouping-functions-sapply-vs-lapply-vs-apply-vs-tapply-vs-by-vs-aggrega?rq= 1)は、* HowardSmithの*適用ファミリーの良い紹介です –