有没有办法将这两个不同的R语句组合起来使它更清洁?
x6 <- subset(dBase, dBase$Operation_Name == "Wash")
x7 <- unique(x6$machine_number)
这有效,但想知道是否有可能将其放在一条线上。
目标是获取machine_number
Operation_Name == "Wash"
谢谢!
答案 0 :(得分:1)
dplyr
解决方案:
df <- data.frame(Operation_Name = c("Wash", "Fold", "Rince"),
machine_number = c(42, 43, 44))
library(dplyr)
df %>%
filter(Operation_Name == "Wash") %>%
pull(machine_number)
# [1] 42
答案 1 :(得分:0)
unique(dBase[dbase$Operation_Name=="Wash",]$machine_number)