RxImport, colClasses and RxTextData
I am trying to import a file csv
using Revolution Analytics.
My code is as follows:
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'))
I took care to remove myXdf
before running the code and use scanning the first 1000 elements to determine the vector colClasses
.
This gives me the following error:
Error in validObject(.Object) :
invalid class "RxTextData" object: 'colClasses' must be a named character vector
Has anyone already met this error?
+3
source to share
1 answer
To specify the column classes for a text data object, you need to add the column names as a named vector.
Try something like this:
# 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)
+2
source to share