Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在dplyr中,如何根据数据帧中是否存在某个列来选择和筛选不同的列?_R_Dataframe_Dplyr - Fatal编程技术网

在dplyr中,如何根据数据帧中是否存在某个列来选择和筛选不同的列?

在dplyr中,如何根据数据帧中是否存在某个列来选择和筛选不同的列?,r,dataframe,dplyr,R,Dataframe,Dplyr,我需要从数据帧中提取一些行和列: 图书馆弹琴 foo这避免了一些重复,但它是否更优雅或可读性有待商榷 图书馆弹琴 计算流行曲线数据1 SVN斯洛文尼亚282 141 计算流行曲线数据,SVN >一个tibble:1 x 3 >iso3c国家认证 > >1 SVN斯洛文尼亚141 由v0.3.0于2020年7月11日创建,这避免了一些重复,但是否更优雅或可读性仍有争议 图书馆弹琴 计算流行曲线数据1 SVN斯洛文尼亚282 141 计算流行曲线数据,SVN >一个tibbl

我需要从数据帧中提取一些行和列:

图书馆弹琴
foo这避免了一些重复,但它是否更优雅或可读性有待商榷

图书馆弹琴 计算流行曲线数据1 SVN斯洛文尼亚282 141 计算流行曲线数据,SVN >一个tibble:1 x 3 >iso3c国家认证 > >1 SVN斯洛文尼亚141
由v0.3.0于2020年7月11日创建,这避免了一些重复,但是否更优雅或可读性仍有争议

图书馆弹琴 计算流行曲线数据1 SVN斯洛文尼亚282 141 计算流行曲线数据,SVN >一个tibble:1 x 3 >iso3c国家认证 > >1 SVN斯洛文尼亚141
由v0.3.0于2020年7月11日创建。在tidyverse选择函数中,在可能的列名之间动态选择的惯用方法是使用tidyselect::任意_:

导致

打印结果A TIBLE:1 x 3 >iso3c国家认证 > >1 SVN斯洛文尼亚141 打印结果:1 x 4 >id已确认管理区域测试 > >1 SVN 141斯洛文尼亚282
在tidyverse选择函数中,在可能的列名之间动态选择的惯用方法是使用tidyselect::any_of:

导致

打印结果A TIBLE:1 x 3 >iso3c国家认证 > >1 SVN斯洛文尼亚141 打印结果:1 x 4 >id已确认管理区域测试 > >1 SVN 141斯洛文尼亚282 我们也可以在匹配项中使用filter_

-测试

compute_epidemic_curve_data(foo, "SVN")
# A tibble: 1 x 3
#  iso3c country  confirmed
#  <chr> <chr>        <dbl>
#1 SVN   Slovenia       141


compute_epidemic_curve_data(bar, "SVN")
# A tibble: 1 x 4
#  id    admin_region confirmed tests
#  <chr> <chr>            <dbl> <dbl>
#1 SVN   Slovenia           141   282
我们也可以在匹配项中使用filter_

-测试

compute_epidemic_curve_data(foo, "SVN")
# A tibble: 1 x 3
#  iso3c country  confirmed
#  <chr> <chr>        <dbl>
#1 SVN   Slovenia       141


compute_epidemic_curve_data(bar, "SVN")
# A tibble: 1 x 4
#  id    admin_region confirmed tests
#  <chr> <chr>            <dbl> <dbl>
#1 SVN   Slovenia           141   282

您的if语句是否应该排除选择“tests”的选项?@Peter good catch-是的,它应该。我会解决这个问题。你的if语句是否应该排除选择“tests”的选项?@petergood-catch-是的,它应该。我来解决这个问题。
compute_epidemic_curve_data(foo, "SVN")
# A tibble: 1 x 3
#  iso3c country  confirmed
#  <chr> <chr>        <dbl>
#1 SVN   Slovenia       141


compute_epidemic_curve_data(bar, "SVN")
# A tibble: 1 x 4
#  id    admin_region confirmed tests
#  <chr> <chr>            <dbl> <dbl>
#1 SVN   Slovenia           141   282