我正在使用R对我的数据执行大数据分析(C5.0或神经网络),该数据是使用R.matlab包从Matlab导入的。由于每个参与者的结果是136x137相关矩阵,我创建了对应于每个参数的变量(因此变量sub001将包含主题1的矩阵,变量sub002将包含主题2的变量,依此类推)。之后,我想将矩阵转换为向量。
假设我有矩阵到矢量转换的代码,那么:
vector <- mat2vec(matrix)
所以我写了以下代码:
#transforming the correlation matrix to 1D vectors
for (i in 1:n){
if (i < 10){
vecName <- paste("sub00",i,"_vec",sep = "")
matName <- paste("sub00",i,"$Z",sep = "")#Z is the subset corresponding to the correlation matrix in the entire data set from Matlab
}
if (i >= 10 && i < 100){
vecName <- paste("sub0",i,"_vec",sep = "")
matName <- paste("sub0",i,"$Z",sep = "")#Z is the subset corresponding to the correlation matrix in the entire data set from Matlab
}
if (i >= 100 && i < 1000){
vecName <- paste("sub",i,"_vec",sep = "")
matName <- paste("sub",i,"$Z",sep = "")#Z is the subset corresponding to the correlation matrix in the entire data set from Matlab
}
assign(vecName,mat2vec(matName))
}
然而,它不起作用,因为它报告R将mat2vec函数中的matName视为字符串“sub001 $ Z”而不是数组sub001中的相关矩阵。任何人都可以向我提出一些关于如何修改编码以使其有效的建议吗?