【问题标题】:Why do I get address must be a character error when I call this api using R?当我使用 R 调用此 api 时,为什么我得到地址必须是字符错误?
【发布时间】:2019-07-16 00:39:04
【问题描述】:
library(ZillowR)
library(tidyverse)

#Try
# Sample data
set_zillow_web_service_id("X1-ZWz17seirkzuh7_93aho")

map2_dfr(sample3$Street, sample3$ZipCode,
         ~{GetDeepSearchResults(address = .x,
                                citystatezip = as.character(.y),
                                rentzestimate=FALSE) %>% 
             unlist() %>% 
             enframe()
         }) %>% 
  filter(!str_detect(value, "text"))

使用数据意大利面的样本数据:

tibble::tribble(
  ~AccountId, ~ZipCode, ~Totalestimate, ~ZipHhIncome,                ~Street, ~State, ~xxxxxxxxxxxxPct, ~ZipPctAdvDegree, ~AgeFactorPct,             ~City,
      464641,    43130,             0,        46205,    "2577 Long Bow Ave",   "OH",             0.8,      0.058499952,           0.7,       "Lancaster",
      451304,    44718,             0,        69396,    "4822 Armandale Nw",   "OH",             0.8,      0.171958907,           0.7,          "Canton",
      443925,     8837,             0,        74764,    "348 Grandview Ave",   "NJ",               1,       0.16989858,           0.7,          "Edison",
      464725,     2032,           147,       100658,       "81 Rhoades Ave",   "MA",             1.3,      0.247449819,           0.7,    "East Walpole",
      431671,    89403,        335.86,        55248, "296 Monte Cristo Dr.",   "NV",             0.8,      0.066260613,           0.7,          "Dayton",
      474844,    99703,         61.05,        53031,      "4348 9th Street",   "AK",            1.05,      0.061620898,           0.8, "Fort Wainwright",
      440990,    55429,             0,        43835, "5649 Vera Cruz Ave N",   "MN",               1,      0.050472833,           0.7,         "Crystal"
  )

如何获取 getdeepsearchresults api 的输出?我希望我的查询命中 api 并返回每行参数的结果,即地址(街道)和邮政编码(citystatezip)

【问题讨论】:

    标签: r api zillow


    【解决方案1】:

    获取addresscitystatezip 的一种方法是使用map2_df/map2_dfr 并将StreetZipCode 传递给GetDeepSearchResults 并仅提取感兴趣的属性。

    library(ZillowR)
    
    purrr::map2_df(sample$Street, as.character(sample$ZipCode), ~{
            temp <- GetDeepSearchResults(address = .x,citystatezip = .y)
           tibble(Address = temp$request$address, Zip = temp$request$citystatezip)
    })
    
    # A tibble: 7 x 2
    #  Address              Zip  
    #  <chr>                <chr>
    #1 2577 Long Bow Ave    43130
    #2 4822 Armandale Nw    44718
    #3 348 Grandview Ave    8837 
    #4 81 Rhoades Ave       2032 
    #5 296 Monte Cristo Dr. 89403
    #6 4348 9th Street      99703
    #7 5649 Vera Cruz Ave N 55429
    

    或者使用基础 R Map

    do.call(rbind, Map(function(x, y) {
       temp <- GetDeepSearchResults(address = x,citystatezip = y)
       c(Address = temp$request$address, Zip = temp$request$citystatezip)
    }, sample$Street, as.character(sample$ZipCode)))
    

    【讨论】:

    • 嗨@ronak 我尝试了base R map 和purr 但得到了这个错误-sample$Street 中的错误:'closure' 类型的对象不是子集
    • @user10007925 因为您的数据框可能被称为 sample3 ?抱歉,我使用 sample 作为数据框名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 2020-10-05
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多