使用替代 %in% 的子集数据

subset data using an alternative to %in%

在下面的示例中,是否可以使用 %in%dosetimesdoserows 进行子集化?我想使用其他东西的原因是因为我在我正在开发的 R 包示例中添加了这部分,并且似乎不接受示例代码中的 %in%

#Set dose records:
dosetimes <- c(0,12)
#set number of subjects
ID <- 1:2
#Make dataframe: CLCR: is creatinine clearance
df <- expand.grid("ID"=ID,"TIME"=sort(unique(c(seq(0,24,1),dosetimes))),"AMT"=0,"DV"=NA)
doserows <- subset(df, TIME%in%dosetimes)

来自R extensions manual

Because backslashes, braces and percent symbols have special meaning, to enter them into text sometimes requires escapes using a backslash. In general balanced braces do not need to be escaped, but percent symbols always do, except in the ‘verbatim’ variant. For the complete list of macros and rules for escapes, see “Parsing Rd files”.

所以试试

doserows <- subset(df, TIME \%in\% dosetimes)

在您的 .Rd 文件或 roxygen 格式的示例中。