无法将txt加载为数字矩阵

时间:2016-01-28 20:53:31

标签: r

以下代码是将我的矩阵(在float / double中)加载到R脚本中。但最终的矩阵不是数字。我的代码出了什么问题?有人可以帮忙吗?

datdir = paste(getwd(), '/../dat/', sep="")
trainX = read.table(paste(datdir, 'trainX.txt', sep=""), header=FALSE)
trainL = read.table(paste(datdir, 'trainL.txt', sep=""), header=FALSE)
testX = read.table(paste(datdir, 'testX.txt', sep=""), header=FALSE)
testL = read.table(paste(datdir, 'testL.txt', sep=""), header=FALSE)
dims = dim(trainX)
trainX = as.numeric(trainX)
dim(trainX) = dims

dims = dim(trainL)
trainL = as.numeric(trainL)
dim(trainL) = dims

dims = dim(testX)
testX = as.numeric(testX)
dim(testX) = dims

dims = dim(testL)
trainX = as.numeric(testL)
dim(testL) = dims

0 个答案:

没有答案