Learn R Programming

expss (version 0.5.5)

write_labels: Write data with labels to file in R code or in SPSS syntax.

Description

write_labelled_* functions write data in the CSV format and file with R code/SPSS syntax for labelling data. SPSS syntax also contains code for reading data in SPSS. write_labelled_* doesn't save rownames of data.frame. write_labels_* functions write R code/SPSS syntax for labelling data. It allows to extract labels from *.sav files that come without accompanying syntax. read_labelled_csv reads data file in CSV format and apply labels from accompanying file with R code.

Usage

write_labels(x, filename, fileEncoding = "")
read_labelled_csv(filename, fileEncoding = "", ...)
write_labelled_csv(x, filename, fileEncoding = "", ...)
write_labelled_spss(x, filename, fileEncoding = "", ...)
write_labels_spss(x, filename)

Arguments

x
data.frame to be written/data.frame whose labels to be written
filename
the name of the file which the data are to be read from/write to.
fileEncoding
character string: if non-empty declares the encoding to be used on a file (not a connection) so the character data can be re-encoded as they are written. See file.
...
additional arguments for read.table/write.table

Value

Functions for writing invisibly return NULL. Functions for reading return labelled data.frame.

Examples

Run this code
## Not run: 
# data(mtcars)
# mtcars = modify(mtcars,{
#                 var_lab(mpg) = "Miles/(US) gallon"
#                 var_lab(cyl) = "Number of cylinders"
#                 var_lab(disp) = "Displacement (cu.in.)"
#                 var_lab(hp) = "Gross horsepower"
#                 var_lab(drat) = "Rear axle ratio"
#                 var_lab(wt) = "Weight (lb/1000)"
#                 var_lab(qsec) = "1/4 mile time"
#                 var_lab(vs) = "Engine"
#                 val_lab(vs) = c("V-engine" = 0, 
#                                 "Straight engine" = 1) 
#                 var_lab(am) = "Transmission"
#                 val_lab(am) = c(automatic = 0, 
#                                 manual=1)
#                 var_lab(gear) = "Number of forward gears"
#                 var_lab(carb) = "Number of carburetors"
# })
# 
# # to R code
# # rownames are not preserved
# write_labelled_csv(mtcars, "mtcars.csv")
# new_mtcars = read_labelled_csv("mtcars.csv")
# 
# # to SPSS syntax
# write_labelled_spss(mtcars, "mtcars.csv")
# 
# ## End(Not run)

Run the code above in your browser using DataLab