Description Usage Arguments Details Value Author(s) Examples
These functions read and write Winsteps data files, where formatting is specified in a command file object.
1 2 3 | write.wdat(x, cmd, datfile = cmd$data, na = " ")
read.wdat(cmd, datfile = cmd$data, na = " ", ilabels = NULL)
|
x |
data frame of item responses |
cmd |
command file object |
datfile |
path to which the data file will be written, or from which it will be read, defaulting to the path supplied in the command file |
na |
character representing missing data, defaulting to a blank space |
ilabels |
vector of new item labels to be added to the item columns, overriding cmd$labels |
When reading data, the person names should occupy 1 column and each item should occupy 1 column in the file. A warning is returned if any rows have fewer than the maximum number of columns and the person names are not in the last column, in which case the missing information pertains to items. ilabels
will override the item labels in cmd$labels
, if they exist. If both are NULL
, generic item names are supplied.
When writing data, all unnamed columns are assumed to be item responses. If the command file contains item labels they will be used to extract and reorder the item responses from x
and all other columns in x
will be ignored, except for the person IDs which must have a column name of "name"
. The data are written to the filename datfile
in fixed width format according to the item1
, ni
, name1
, and namelen
command file components.
read.wdat
returns a data frame
Anthony Albano tony.d.albano@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Simulate data, with missings
set.seed(82911)
b <- seq(-3, 3, length = 15)
theta <- rnorm(100, 1)
rmat <- ifelse(rirf(b, theta)$p > runif(1500), 1, 0)
rmat[sample(1500, 30)] <- NA
rmat <- data.frame(rmat)
# Item and person labels
colnames(rmat) <- paste("i", 1:15, sep = "")
rmat$name <- paste("p", 1:100, sep = "")
# Create command file
tempdat <- tempfile()
cmd <- wcmd(title = "R2Winsteps Example", data = tempdat,
item1 = 1, ni = 15, name1 = 16, namelen = 5,
labels = paste("i", 1:15, sep = ""), hlines = "Y")
# Write to temp file and read back in
write.wdat(rmat, cmd, na = "N")
rmat2 <- read.wdat(cmd, na = "N")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.