我正在尝试使用Revolution Analytics导入csv
文件。
我的代码如下:
rxImport(inData = mycsv, outFile =myXdf,type="text", colClasses=c('character','character','character','character',
'character','character' ,'character','logical','logical','logical','logical', 'logical','logical','logical', 'logical','logical','logical' ,'numeric','numeric', 'numeric'))
我在启动代码之前注意删除myXdf
,并在前1000个元素上使用扫描来定义向量colClasses
。
它给了我以下错误:
Error in validObject(.Object) :
invalid class “RxTextData” object: 'colClasses' must be a named character vector
有人已经遇到过这个错误吗?
答案 0 :(得分:2)
要指定文本数据对象的列类,需要将列名称添加为命名向量。
尝试这样的事情:
# Read first few lines of csv to determine column names
x <- read.csv(mycsv, nrow=5)
# Define desired column classes
colClasses=c('character','character','character','character', 'character','character' ,'character','logical','logical', 'logical','logical', 'logical','logical','logical', 'logical','logical','logical' ,'numeric','numeric', 'numeric')
# Assign csv column names
names(colClasses) <- names(x)
# Define input object
input <- RxTextData(mycsv, colClasses = colClasses)
# Import the data
rxImport(input, myxdf)