我正在编写一个长脚本,它采用一个简单的标准来处理气象数据,例如计算每年30度以上的总天数,我只想输入一次标准,存储为对象,比如:
var <- "V2 > 0"
在脚本顶部输入;问题是当我把它传递给
时 count(criterion = var)
它被读作字符并返回NaNs,我试过unquote(),as.name()没有给出结果,as.factor()给出了错误的结果, 我的数据样本:
station = structure(list(V1 = structure(1:10, .Label = c("18/06/1982",
"19/06/1982", "20/06/1982", "21/06/1982", "22/06/1982", "23/06/1982",
"24/06/1982", "25/06/1982", "26/06/1982", "27/06/1982"), class = "factor"),
V2 = c(0, 0, 0, 0, 3.5, 2.2, 0, 0, 1, 1.1)), .Names = c("V1",
"V2"), row.names = c(NA, 10L), class = "data.frame")
我正在尝试运行的代码(通过用对象var
替换V2&gt; 0):
library(dplyr)
library(lubridate)
station %>% mutate(V1=dmy(station$V1, tz="America/Mexico_City")) %>%
group_by(year(V1)) %>% count(criterion = V2 > 0 ) %>% filter(criterion == T) %>%
colMeans(na.rm = T)
答案 0 :(得分:0)
您可以使用表达式和recvmsg(fd, &hdr, MSG_PEEK | MSG_TRUNC)
:
!!