为了完成 R 与 Minitab Statistical Software 的集成,Minitab, LLC. 提供了 mtbr 包。有关 mtbpy 包的类和方法的以下说明可帮助您为编写与 Minitab 集成的 R 代码做好准备。

有关如何安装 Minitab 的 R 包以及如何从 Minitab 运行 R 的信息,请转到 安装要与 Minitab Statistical Software 配合使用的 R

有关 R 的详细信息,请查阅 www.r-project.org 提供的指南。

Package: mtbr

mtb_get_column

从 Minitab 工作表中检索要在 R 中使用的列。

name: character
指定要检索的列。您可以指定列号(例如,“C1”)或列名称(例如,“我的列”)。
返回值
将活动工作表中的数据列作为 Ratomic vector 返回。这些可以 atomic vector 包含字符或数字值。
示例
library(mtbr) column1 <- mtb_get_column("C1") column2 <- mtb_get_column("My Column")

mtb_get_constant

从 Minitab 工作表中检索要在 R 中使用的常量。

name: character
指定要检索的常量。您可以指定常量编号(例如,“K1”)或常量名称(例如,“我的常量”)。
返回值
返回的常量可以是字符、整数或数字值。
示例
library(mtbr) constant1 <- mtb_get_constant("K1") constant2 <- mtb_get_constant("My Constant")

mtb_get_matrix

从 Minitab 工作表中检索要在 R 中使用的矩阵。

name: character
指定要检索的矩阵。您可以指定矩阵编号(例如,“M1”)或矩阵名称(例如,“我的矩阵”)。
返回值
将矩阵中的数据作为 Rmatrix 返回。
示例
library(mtbr) matrix1 <- mtb_get_matrix("M1") matrix2 <- mtb_get_matrix("My Matrix")

mtb_add_message

将消息添加到 Minitab“输出”窗格。

message: character
string
返回值
Null
示例
library(mtbr) mtb_add_message("This is a message.")

mtb_set_note

在 Minitab“输出”窗格的顶部设置注释。

note: character
string
返回值
Null
示例
library(mtbr) mtb_set_note("The output contains one note.")

mtb_set_title

在 Minitab“输出”窗格的顶部设置标题。

title: character
string
返回值
Null
示例
library(mtbr) mtb_set_title("The output contains one title.")

mtb_add_image

当您有受支持的图像文件时,将图像添加到 Minitab“输出”窗格中。

filename: character
character
返回值
Null
示例
library(mtbr) png("histogram.png") hist(airquality$Temp) dev.off() mtb_add_image("histogram.png")

mtb_add_image_bytes

当您有字节对象时,将图像添加到 Minitab“输出”窗格中。

image_bytes: raw vector
指定图像的数据字节。例如,你可以输入 a raw vector 作为参数。
返回值
Null
示例
library(mtbr) image_data <- as.raw(c(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x08, 0x02, 0x00, 0x00, 0x00, 0x6f, 0xf3, 0x91, 0x47, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, 0x00, 0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x00, 0xb1, 0x8f, 0x0b, 0xfc, 0x61, 0x05, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x16, 0x25, 0x00, 0x00, 0x16, 0x25, 0x01, 0x49, 0x52, 0x24, 0xf0, 0x00, 0x00, 0x00, 0x22, 0x49, 0x44, 0x41, 0x54, 0x18, 0x57, 0x63, 0xd8, 0x61, 0xbb, 0x8b, 0x81, 0x01, 0x27, 0x49, 0xba, 0x04, 0x01, 0x69, 0x9c, 0x12, 0x04, 0xa4, 0x71, 0x4a, 0x10, 0x90, 0xc6, 0x29, 0xb1, 0xc3, 0x76, 0x17, 0x00, 0xfc, 0x0b, 0x45, 0x08, 0x6f, 0x2c, 0xff, 0xe2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82)) mtb_add_image_bytes(image_data)

mtb_add_table

将表格添加到 Minitab“输出”窗格。

columns: data.frame or list of atomic vectors
将表格的数据列指定为 atomic vectorslist 或者 data.frame
headers: character vector (Optional)
指定表格的列标题。默认headers为空 character vector
title: character (Optional)
指定表格的标题。默认title""
footnote: character (Optional)
在表格下方指定脚注。默认footnote""
返回值
Null
示例
library(mtbr) mytitle <- "Air Quality Data" myheaders <- names(airquality) mycolumns <- airquality myfootnote <- gsub("\"", "", paste0(capture.output(summary(airquality)[4,]), collapse = "\n")) mtb_add_table(columns=mycolumns, headers=myheaders, title=mytitle, footnote=myfootnote)

从 Minitab 日期格式转换为 R 日期格式

默认情况下,Minitab 使用的 datetime 格式与 R 不同。要从 Minitab datetime 格式转换为 Unix datetime 格式,请使用 janitorR 包中的 excel_numeric_to_date() 函数。

结合字符集的错误 Microsoft® Windows

R 在 Microsoft® WindowsR 上无法总是处理包含不同字符集字符的字符串。例如,如果 Microsoft® Windows 使用日语(Shift-JIS)字符集,且字符串包含中文(GBK)字符集,部分字符串将无法正确处理。

由于这一限制,一种可能的解决方案是字符串使用与 Microsoft® Windows 显示语言相同的字符集字符。