问题
I'm trying to find out what these functions do but I can't find much information on it and it is not very clear from what I have found out. can you help explain what they do?
Thanks in advance
回答1:
When you start out using Revo R or see demonstrations given, it's common to see functions being applied directly to a file path, like this:
# Create a point to an insurance claims dataset installed with RRE
xdfPath <- file.path(rxGetOption("sampleDataDir"), "claims.xdf")
rxDataStep(xdfPath, numRows = 6)
Behind the scenes, though, rxDataStep
is creating a wrapper around that file path with the information it needs to work with it - the file type, which variables to read, whether character vectors should be converted to factors, etc. That wrapper is called a "data source", and RxXdfData
is the function used to create it. RxTextData
is the same thing, just for text files:
# Create a point to an insurance claims dataset installed with RRE
textPath <- file.path(rxGetOption("sampleDataDir"), "claims.txt")
rxDataStep(textPath, numRows = 6)
You can often just let the RRE functions take care of this for you. Creating a data source can be useful if you have a file that should have different default settings in different analyses. They also have one other advantage: because a data source is a real R object, instead of just a file path, you can use a handful open-source R functions on them:
# This doesn't work like we'd expect:
head(xdfPath)
# These do:
xdfSource <- RxXdfData(xdfPath)
head(xdfSource)
names(xdfSource)
nrow(xdfSource)
summary(xdfSource)
Which is neat but not world-changing.
rxXdfToDataFrame
just lets you convert an XDF file into an in-memory data frame, like this:
rxXdfToDataFrame(xdfSource)
... which is also what rxDataStep
does if you don't give it an outFile
, so I usually use rxDataStep
because it's easier to type.
Hope this helps!
来源:https://stackoverflow.com/questions/31904835/rxxdfdata-rxtextdata-rxxdftodataframe