Create Tables in R: Step-by-Step Tutorial

In R language, you can create a table object using the table function, and then use the print function to display the table.

Here is an example:

# 创建表格对象
table_data <- table(c("A", "B", "A", "C", "B"))

# 打印表格
print(table_data)

This will produce the following outcome:

A B C 
2 2 1 

To create a more visually appealing table, you can utilize the kable function from the knitr package.

Here is an example:

# 安装knitr包(如果尚未安装)
# install.packages("knitr")

# 加载knitr包
library(knitr)

# 创建表格对象
table_data <- table(c("A", "B", "A", "C", "B"))

# 将表格绘制成更美观的形式
kable(table_data)

This will produce a more visually appealing table format.

| . | Freq |
|---|------|
| A |    2 |
| B |    2 |
| C |    1 |
bannerAds