我在R中使用strsplit为boxplot添加名称,但这给了我一个错误。
strng <- "one%two%three"
tt <- strsplit(strng,"%",fixed=TRUE)
然后
boxplot(param~grp,data=snp,horizontal=TRUE,names=tt)
这会产生
ls = list(c("one", "two", :
'at' and 'labels' lengths differ, 3 != 1
Calls: boxplot ... boxplot.default -> do.call -> bxp -> do.call -> axis
Execution halted
names参数需要一个向量,而strsplit返回一个列表。这些不相容吗?
如果我这样做
boxplot(param~grp,data=snp,horizontal=TRUE,names=c("on","two","three"))
然后就可以了。
非常感谢你的帮助
答案 0 :(得分:3)
使用tt[[1]]
或unlist(tt)
代替tt
boxplot(param~grp,data=snp,horizontal=TRUE,names=tt[[1]])
names
参数期望一个向量,tt
是一个列表,因此您需要传递一个不是列表的向量。