我还有另一个 R 问题。我正在尝试进行一些类型检查,但无法完全弄清楚我做错了什么。
我正在尝试为 y 的每个级别创建一个直方图。因此,例如,我想创建鸢尾花数据种类及其萼片宽度等的叠加直方图
这是我迄今为止所拥有的:
#if x isn't numeric
if(!is.numeric(x)){
#if y isn't a factor
}else if(!is.factor(y)){
#if the length of x isn't equal to y
}else if(nChar(x) != nChar(y)){
#error message
stop('x is not numeric/y is not a factor/both x and y are the same length')
}
#otherwise create histogram
#testing with iris data set
hist(y, main = "Iris Species", xlab = "Sepal Width", col = "orange", border ="blue")
Run Code Online (Sandbox Code Playgroud)