R 从嵌套列表中提取特定变量的值,并将提取的值列附加到原始数据集中

R 从嵌套列表中提取特定变量的值,并将提取的值列附加到原始数据集中,r,R,我有我的原始数据集 agriculturestru~ asofdate basefloodelevat~ basementenclosu~ reportedcity condominiumindi~ policycount countycode crsdiscount <chr> <date> <dbl> <dbl> <chr> <c

我有我的原始数据集

agriculturestru~ asofdate   basefloodelevat~ basementenclosu~ reportedcity condominiumindi~ policycount countycode crsdiscount
   <chr>            <date>                <dbl>            <dbl> <chr>        <chr>                  <dbl> <chr>            <dbl>
 1 NA               2019-08-31               NA                4 WESTPORT     NA                         1 09001                0
 2 NA               2019-08-31               10                4 W HAMPTON B~ NA                         1 36103                0
 3 NA               2019-08-31               NA                3 BRONX        NA                         1 36005                0
 4 NA               2019-08-31               NA                4 MASSAPEQUA   NA                         1 36059                0
 5 NA               2019-08-31               NA                4 STATEN ISLE  NA                         1 36085                0
 6 NA               2019-08-31                7                4 GARDEN CITY  NA                         1 36059                0
 7 NA               2019-08-31                7                4 YONKERS      NA                         1 36119                0
 8 NA               2019-08-31                7                4 GARDEN CITY  NA                         1 36059                0
 9 NA               2019-08-31               NA                4 LOGAN        NA                         1 54045                0
10 NA               2019-08-31               NA                4 HARAHAN      NA                         1 22051                0
# ... with 918,923 more rows, and 34 more variables: dateofloss <date>, elevatedbuildingindicator <chr>,
#   elevationcertificateindicator <dbl>, elevationdifference <dbl>, censustract <chr>, floodzone <chr>, houseworship <chr>,
#   latitude <dbl>, locationofcontents <chr>, longitude <dbl>, lowestadjacentgrade <dbl>, lowestfloorelevation <dbl>,
#   numberoffloorsintheinsuredbuilding <dbl>, nonprofitindicator <chr>, obstructiontype <dbl>, occupancytype <dbl>,
#   originalconstructiondate <date>, originalnbdate <date>, amountpaidonbuildingclaim <dbl>, amountpaidoncontentsclaim <dbl>,
#   amountpaidonincreasedcostofcomplianceclaim <dbl>, postfirmconstructionindicator <chr>, ratemethod <chr>,
#   smallbusinessindicatorbuilding <chr>, state <chr>, totalbuildinginsurancecoverage <dbl>,
#   totalcontentsinsurancecoverage <dbl>, yearofloss <dbl>, reportedzipcode <chr>, primaryresidence <chr>, totalpaid <dbl>,
#   totalcoverage <dbl>, station_id <chr>, station_name <chr>'''
agriculturestru~asofdate basefloodlevat~basementenclosuru~reportedcity condominiumini~policycount county代码CRS折扣
1北美2019-08-31北美4西港北美1 09001 0
2 NA 2019-08-31104西汉普顿B~NA 1361030
3北美2019-08-31北美3布朗克斯北美1 36005 0
4北美2019-08-31北美4马萨佩卡北美1 36059 0
5北美2019-08-31北美4斯塔顿岛北美1 36085 0
6 NA 2019-08-31 7 4花园城NA 1 36059 0
7北美2019-08-317 4扬克斯北美1361190
8 NA 2019-08-31 7 4花园城NA 1 36059 0
9 NA 2019-08-31 NA 4洛根NA 1 54045 0
10 NA 2019-08-31 NA 4哈拉罕NA 1 22051 0
# ... 还有918923行和34个变量:dateofloss、elevatedbuildingindicator、,
#高程证书指示器、高程差、检查员、洪水区、家庭作业、,
#纬度、内容物位置、经度、最低相邻等级、最低楼层相关度、,
#被保险建筑物的楼层数、非专业指标、障碍物类型、职业类型、,
#原始施工日期,原始施工日期,建筑索赔的付款金额,付款内容索赔的付款金额,
#支付金额增加合规性索赔、确定后施工指标、费率方法、,
#SmallBusinessIndicator建筑、州、总建筑保险范围,
#保险范围内的总内容、损失年份、报告的ZIPCODE、主要居住地、总支付、,
#总覆盖率、站点id、站点名称“”
我有10个输出列表,其中40个元素来自一个函数

> List of 40
 $ US1CTFR0035:List of 1
  ..$ prcp:Classes ‘tbl_df’, ‘tbl’ and 'data.frame':    1006 obs. of  6 variables:
  .. ..$ id   : chr [1:1006] "US1CTFR0035" "US1CTFR0035" "US1CTFR0035" "US1CTFR0035" ...
  .. ..$ prcp : int [1:1006] NA NA 140 0 137 0 0 28 0 8 ...
  .. ..$ date : Date[1:1006], format: "2016-04-01" "2016-04-02" "2016-04-03" "2016-04-04" ...
  .. ..$ mflag: chr [1:1006] " " " " " " "T" ...
  .. ..$ qflag: chr [1:1006] " " " " " " " " ...
  .. ..$ sflag: chr [1:1006] " " " " "N" "N" ...
  .. ..- attr(*, ".internal.selfref")=<externalptr> 
 $ US1NYSF0080:List of 1
  ..$ prcp:Classes ‘tbl_df’, ‘tbl’ and 'data.frame':    853 obs. of  6 variables:
  .. ..$ id   : chr [1:853] "US1NYSF0080" "US1NYSF0080" "US1NYSF0080" "US1NYSF0080" ...
  .. ..$ prcp : int [1:853] NA 33 0 0 0 0 28 5 0 18 ...
  .. ..$ date : Date[1:853], format: "2016-09-01" "2016-09-02" "2016-09-03" "2016-09-04" ...
  .. ..$ mflag: chr [1:853] " " " " " " " " ...
  .. ..$ qflag: chr [1:853] " " " " " " " " ...
  .. ..$ sflag: chr [1:853] " " "N" "N" "N" ...
  .. ..- attr(*, ".internal.selfref")=<externalptr> 
>40人名单
$US1CTFR0035:1个
..$prcp:class'tbl_df'、'tbl'和'data.frame':1006 obs。共有6个变量:
.. ..$ id:chr[1:1006]“US1CTFR0035”“US1CTFR0035”“US1CTFR0035”“US1CTFR0035”。。。
.. ..$ prcp:int[1:1006]NA1400137002808。。。
.. ..$ 日期:日期[1:1006],格式:“2016-04-01”“2016-04-02”“2016-04-03”“2016-04-04”。。。
.. ..$ mflag:chr[1:1006]“T”。。。
.. ..$ qflag:chr[1:1006]“”。。。
.. ..$ sflag:chr[1:1006]“N”N。。。
.. ..- 属性(*,“.internal.selfref”)=
$US1NYSF0080:1个
..$prcp:class'tbl_df'、'tbl'和'data.frame':853 obs。共有6个变量:
.. ..$ id:chr[1:853]“US1NYSF0080”“US1NYSF0080”“US1NYSF0080”“US1NYSF0080”“US1NYSF0080”。。。
.. ..$ prcp:int[1:853]NA 33 0 0 0 0 28 5 0 18。。。
.. ..$ 日期:日期[1:853],格式:“2016-09-01”“2016-09-02”“2016-09-03”“2016-09-04”。。。
.. ..$ mflag:chr[1:853]“”。。。
.. ..$ qflag:chr[1:853]“”。。。
.. ..$ sflag:chr[1:853]“N”N“N”。。。
.. ..- 属性(*,“.internal.selfref”)=
我想提取并合并所有10个输出数据,并根据以下条件向原始数据集追加一列:data$station\u id==alloutput$id&data$dateofloss==alloutput$date


data$prcp也许,我们需要加入数据集

library(dplyr)
library(purrr)
lst2 <-  map(lst1, ~ .x %>% 
            left_join(data, by = c("id" = "station_id",  "date" = "dateofloss")))
库(dplyr)
图书馆(purrr)
lst2%
左连接(数据,by=c(“id”=“station\u id”,“date”=“dateofloss”))

也许,我们需要加入数据集

library(dplyr)
library(purrr)
lst2 <-  map(lst1, ~ .x %>% 
            left_join(data, by = c("id" = "station_id",  "date" = "dateofloss")))
库(dplyr)
图书馆(purrr)
lst2%
左连接(数据,by=c(“id”=“station\u id”,“date”=“dateofloss”))

这两个都是
列表
我的数据集是一个数据框,我有10个列表,其中40个嵌套列表。我尝试了
list2=out1[[1]]lapply(2:length(out1),function(I){list2=rbind(list2,as.data.frame(out1[[I]]))}
但是R只返回第一个嵌套列表。这两个都是
列表吗
我的数据集是一个数据帧,我有10个40个嵌套列表。我尝试了
list2=out1[[1]]lapply(2:length(out1),function(I){list2=rbind(list2,as.data.frame(out1[[I]]))})
但是R只返回第一个嵌套列表。