Learn R Programming

misty (version 0.6.7)

read.mplus: Read Mplus Data File and Variable Names

Description

This function reads a Mplus data file and/or Mplus input/output file to return a data frame with variable names extracted from the Mplus input/output file. Note that by default -99 in the Mplus data file is replaced with to NA.

Usage

read.mplus(file, sep = "", input = NULL, na = -99, print = FALSE, return.var = FALSE,
           encoding = "UTF-8-BOM", check = TRUE)

Value

A data frame containing a representation of the data in the file.

Arguments

file

a character string indicating the name of the Mplus data file with or without the file extension .dat, e.g., "Mplus_Data.dat" or "Mplus_Data". Note that it is not necessary to specify this argument when return.var = TRUE.

sep

a character string indicating the field separator (i.e., delimiter) used in the data file specified in file. By default, the separator is 'white space', i.e., one or more spaces, tabs, newlines or carriage returns.

input

a character string indicating the Mplus input (.inp) or output file (.out) in which the variable names are specified in the VARIABLE: section. Note that if input = NULL, this function is equivalent to read.table(file).

na

a numeric vector indicating values to replace with NA. By default, -99 is replaced with NA. If -99 is not a missing value change the argument to NULL.

print

logical: if TRUE, variable names are printed on the console.

return.var

logical: if TRUE, the function returns the variable names extracted from the Mplus input or output file only.

encoding

character string declaring the encoding used on file so the character data can be re-encoded.See the 'Encoding' section of the help page for the file function, the 'R Data Import/Export Manual' and 'Note'.

check

logical: if TRUE (default), argument specification is checked.

Author

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Muthen, L. K., & Muthen, B. O. (1998-2017). Mplus User's Guide (8th ed.). Muthen & Muthen.

See Also

read.dta, write.dta, read.sav, write.sav, read.xlsx, write.xlsx

Examples

Run this code
if (FALSE) {
# Example 1: Read Mplus data file and variable names extracted from the Mplus input file
dat <- read.mplus("Mplus_Data.dat", input = "Mplus_Input.inp")

# Example 2: Read Mplus data file and variable names extracted from the Mplus input file,
# print variable names on the console
dat <- read.mplus("Mplus_Data.dat", input = "Mplus_Input.inp", print = TRUE)

# Example 3: Read variable names extracted from the Mplus input file
varnames <- read.mplus(input = "Mplus_Input.inp", return.var = TRUE)
}

Run the code above in your browser using DataLab