How can you transpose arrays in R language?

In R language, you can perform array transposition using the transpose() function. Here is a simple example:

# 创建一个矩阵
mat <- matrix(1:6, nrow = 2)

# 输出原始矩阵
print(mat)

# 对矩阵进行转置操作
transposed_mat <- t(mat)

# 输出转置后的矩阵
print(transposed_mat)

In the example above, a matrix mat with 2 rows and 3 columns was first created, then the matrix was transposed using the t() function to obtain the transposed matrix transposed_mat.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds