我有以下O形圈故障数据:0 1 0 NA 0 0 0 0 0 1 1 0 0 3 0 0 0 0 0 2
如何构建一个类别为0 Failure,1 Failure,> 1 Failures?
的表我尝试使用以下代码,但发生错误:
oringfailures <- matrix(c(0, 1, 0, NA, 0, 0, 0, 0, 0, 1, 1, 0, 0, 3, 0, 0, 0, 0, 0, 2),nrow=1, byrow=T, na.rm=T)
table(oringfailures)
colnames(oringfailures)<- c("0 Failure", "1 Failure", ">1 Failures")
这是出现的错误:
Error in `colnames<-`(`*tmp*`, value = c("0 Failure", "1 Failure", ">1 Failures" :
length of 'dimnames' [2] not equal to array extent
答案 0 :(得分:1)
两件事:您需要pmin
大数减至2,dimnames
似乎是在这种情况下设置列标题的正确函数。
orf = c(0,1,0,NA,0,0,0,0,0,1,1,0,0,3,0,0,0,0,0,2)
ort = table(pmin(2,orf)) # map all x>=2 to x=2
dimnames(ort)[[1]] = c("0 Failures","1 Failure",">1 Failures")
ort
#
# 0 Failures 1 Failure >1 Failures
# 14 3 2