user45097
user45097

Reputation:

constructing a table given a data

I have the following data for O-ring failures: 0 1 0 NA 0 0 0 0 0 1 1 0 0 3 0 0 0 0 0 2

How do I construct a table with categories 0 Failure, 1 Failure, and >1 Failures?

I tried using the following codes, but an error occurred:

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")

This is the error that appeared:

Error in `colnames<-`(`*tmp*`, value = c("0 Failure", "1 Failure", ">1 Failures" : 
length of 'dimnames' [2] not equal to array extent

Upvotes: 0

Views: 65

Answers (1)

PythonAteMyHamster
PythonAteMyHamster

Reputation: 186

Two things: you need to pmin the large counts down to 2, and dimnames appears to be the correct function for setting the column headings in this case.

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

Upvotes: 1

Related Questions