【发布时间】:2021-12-30 14:49:16
【问题描述】:
我知道几种从数据框/tibble 中获取单个值的方法。
library(dplyr)
start_date <- tibble::tribble(
~StaffAbbrev, ~starting_date,
"Alexander", "2021-08-23",
"Cornelis", "2021-08-23",
"Sotirchos", "2021-08-23",
"Zhao", "2021-08-23",
"Park", "2022-02-14",
"Sarkar", "2022-04-04"
)
#Tidyverse way
Alexander_start_v1 <- start_date %>%
filter(StaffAbbrev == "Alexander") %>%
select(starting_date) %>%
unlist() %>%
unname()
#Base R way
Alexander_start_v2=start_date$starting_date[start_date$StaffAbbrev=="Alexander"]
从数据框/tibble 中提取单个特定值的速记/更优雅/单行 tidyverse 方法是什么?
【问题讨论】: