小编cli*_*liu的帖子

将排名矩阵 (1 ~ 4) 扩展为更大的二进制矩阵

我有一个矩阵,我想将其转换为二进制输出(0 vs 1)。要转换的矩阵包含四行排名(1 到 4):

mat1.data <- c(4,   3,  3,  3,  3,  2,  2,  1,  1,  1,
               3,   4,  2,  4,  2,  3,  1,  3,  3,  2,
               2,   2,  4,  1,  1,  1,  4,  4,  2,  4,
               1,   1,  1,  2,  4,  4,  3,  2,  4,  3)
mat1 <- matrix(mat1.data,nrow=4,ncol=10,byrow=TRUE)
mat1
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    4    3    3    3    3    2    2    1    1     1
[2,]    3    4    2    4    2    3    1 …
Run Code Online (Sandbox Code Playgroud)

r data-manipulation matrix data-conversion ranking

6
推荐指数
1
解决办法
195
查看次数

相关分类数据和连续数据的模拟

我想模拟相关的分类数据和连续数据。如何在 R 中实现这一点?

#For example, how to simulate the data in a way that these two variable are correlated?
x <- sample( LETTERS[1:4], 1000, replace=TRUE, prob=c(0.1, 0.2, 0.65, 0.05) ) #Categorical variable
y <- runif(1000,1,5) #Continuous variable
Run Code Online (Sandbox Code Playgroud)

任何想法将不胜感激!

simulation r continuous correlation categorical-data

1
推荐指数
1
解决办法
655
查看次数