#load the package
library(qcc)
## Warning: package 'qcc' was built under R version 4.3.3
## Package 'qcc' version 2.7
## Type 'citation("qcc")' for citing this R package in publications.
library(xlsx)
## Warning: package 'xlsx' was built under R version 4.3.3
# Read the Excel file
x <- read.xlsx("S_chart.xlsx", sheetIndex = 1, header = TRUE)
# Convert the data to a data frame
x <- data.frame(x)
# Select the first 25 rows and columns 2 to 6
x_subset <- x[1:25, 2:6]
# Check if the data is numeric; if not, convert it to numeric
x_subset <- as.data.frame(lapply(x_subset, function(col) as.numeric(as.character(col))))
### x bar chart
qcc(x_subset, type = "xbar")

## List of 11
## $ call : language qcc(data = x_subset, type = "xbar")
## $ type : chr "xbar"
## $ data.name : chr "x_subset"
## $ data : num [1:25, 1:5] 74 74 74 74 74 ...
## ..- attr(*, "dimnames")=List of 2
## $ statistics: Named num [1:25] 74 74 74 74 74 ...
## ..- attr(*, "names")= chr [1:25] "1" "2" "3" "4" ...
## $ sizes : int [1:25] 5 5 5 5 5 5 5 5 5 5 ...
## $ center : num 74
## $ std.dev : num 0.00999
## $ nsigmas : num 3
## $ limits : num [1, 1:2] 74 74
## ..- attr(*, "dimnames")=List of 2
## $ violations:List of 2
## - attr(*, "class")= chr "qcc"
# Read the Excel file
x <- read.xlsx("S_chart.xlsx", sheetIndex = 2, header = TRUE)
# Convert the data to a data frame
x <- data.frame(x)
# Select the first 25 rows and columns 2 to 6
x_subset <- x[1:25, 2:6]
# Check if the data is numeric; if not, convert it to numeric
x_subset <- as.data.frame(lapply(x_subset, function(col) as.numeric(as.character(col))))
### x bar chart
qcc(x_subset, type = "xbar")

## List of 11
## $ call : language qcc(data = x_subset, type = "xbar")
## $ type : chr "xbar"
## $ data.name : chr "x_subset"
## $ data : num [1:25, 1:5] 1.32 1.43 1.43 1.5 1.56 ...
## ..- attr(*, "dimnames")=List of 2
## $ statistics: Named num [1:25] 1.51 1.5 1.48 1.47 1.49 ...
## ..- attr(*, "names")= chr [1:25] "1" "2" "3" "4" ...
## $ sizes : int [1:25] 5 5 5 5 5 5 5 5 5 5 ...
## $ center : num 1.51
## $ std.dev : num 0.14
## $ nsigmas : num 3
## $ limits : num [1, 1:2] 1.32 1.69
## ..- attr(*, "dimnames")=List of 2
## $ violations:List of 2
## - attr(*, "class")= chr "qcc"
####### S chart
# You can now use the row_means for an S chart
qcc(x_subset, type = "S")

## List of 11
## $ call : language qcc(data = x_subset, type = "S")
## $ type : chr "S"
## $ data.name : chr "x_subset"
## $ data : num [1:25, 1:5] 1.32 1.43 1.43 1.5 1.56 ...
## ..- attr(*, "dimnames")=List of 2
## $ statistics: Named num [1:25] 0.1635 0.1111 0.0565 0.1389 0.1412 ...
## ..- attr(*, "names")= chr [1:25] "1" "2" "3" "4" ...
## $ sizes : int [1:25] 5 5 5 5 5 5 5 5 5 5 ...
## $ center : num 0.132
## $ std.dev : num 0.14
## $ nsigmas : num 3
## $ limits : num [1, 1:2] 0 0.275
## ..- attr(*, "dimnames")=List of 2
## $ violations:List of 2
## - attr(*, "class")= chr "qcc"