我的宏根据变量值(start_row和end_row)隐藏行。
我有这行代码:
# ADD INDICATOR
dat$indicator <- factor(ifelse(dat$group == 4, 'control', 'treatment'))
# ITERATIVELY EXPAND BY GROUP
df_list <- by(dat, dat$group, function(sub)
transform(rbind(sub, dat[dat$group == 4,]),
new_group = sub$group[[1]])
)
# BIND ALL DFs AND FILTER OUT 4 AND 4 PAIRINGS
graph_df <- subset(do.call(rbind, df_list), new_group != 4)
# PLOT USING fill AND LABEL CLEANUP
ggplot(graph_df, aes(x = as.factor(keyId), y = value, fill=indicator)) +
geom_bar(position = 'dodge', stat = 'identity') +
labs(title="Treatments vs Control Group", x="keyId") +
theme(plot.title = element_text(hjust = 0.5),
legend.position="bottom") +
facet_wrap(~new_group)
对于值start_row = 1和end_row = 5,我希望它执行与以下代码相同的操作:
Worksheets("Exhibit").Rows(""""&start_row&":"&end_row&"""").EntireRow.Hidden = True
虽然出现了“编译错误:预期:列表分隔符或”,但突出显示了该行的“:”部分。
我该如何解决?
答案 0 :(得分:3)
完全舍弃开头和结尾的引号:
Worksheets("Exhibit").Rows(start_row & ":" & end_row).Hidden = True
并且正如@Mark Balhoff所指出的,在“&”号周围添加空格。