if (FALSE) {
# generate a test dataframe with 100 (imaginary) participants / units of
# observation (ID), 8 measurement (measure) of one variable (X)
dtaInp <- data.frame(ID = rep(as.character(seq(1, 100)), each = 8),
measure = rep(seq(1, 8), times = 100),
X = runif(800, -10, 10))
cat(str(dtaInp))
# the output should look like this
# 'data.frame': 800 obs. of 3 variables:
# $ ID : chr "1" "1" "1" "1" ...
# $ measure: int 1 2 3 4 5 6 7 8 1 2 ...
# $ X : num ...
# this data set is stored as (temporary) RDS-file and later processed by long2wide
nmeInp <- tempfile(fileext = ".rds")
nmeOut <- tempfile(fileext = ".omv")
saveRDS(dtaInp, nmeInp)
jmvReadWrite::long2wide_omv(dtaInp = nmeInp, fleOut = nmeOut, varTgt = "X", varID = "ID",
varTme = "measure")
# it is required to give at least the arguments dtaInp, varID and varTme
# check whether the file was created and its size
cat(list.files(dirname(nmeOut), basename(nmeOut)))
# -> "file[...].omv" ([...] contains a random combination of numbers / characters
cat(file.info(nmeOut)$size)
# -> 6851 (approximate size; size may differ in every run [in dependence of
# how well the generated random data can be compressed])
cat(str(jmvReadWrite::read_omv(nmeOut, sveAtt = FALSE)))
# the data set is now transformed into wide (and each the measurements is now
# indicated as a suffix to X; X_1, X_2, ...)
# 'data.frame': 100 obs. of 9 variables:
# $ ID : chr "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" ...
# ..- attr(*, "jmv-id")= logi TRUE
# ..- attr(*, "missingValues")= list()
# $ X_1: num ...
# ..- attr(*, "missingValues")= list()
# $ X_2: num ...
# ..- attr(*, "missingValues")= list()
# $ X_3: num ...
# ..- attr(*, "missingValues")= list()
# $ X_4: num ...
# ..- attr(*, "missingValues")= list()
# $ X_5: num ...
# ..- attr(*, "missingValues")= list()
# $ X_6: num ...
# ..- attr(*, "missingValues")= list()
# $ X_7: num ...
# ..- attr(*, "missingValues")= list()
# $ X_8: num ...
# ..- attr(*, "missingValues")= list()
unlink(nmeInp)
unlink(nmeOut)
}
Run the code above in your browser using DataLab