to_px: Convert a data cube from data frame to a px file

View source: R/to_px.R

to_pxR Documentation

Convert a data cube from data frame to a px file

Description

Convert a data cube from data frame to a px file

Usage

to_px(.cube, vars, measure_vars, measure_name)

to_px2(.cube, vars, measure_vars, measure_name = NULL,
  .symbols = c("X", "...", "()"), TITLE = "Title unknown",
  PRECISION = NULL, SHOWDECIMALS = 0, info = "info")

to_px5(.cube, vars, measure_vars, measure_name = NULL,
  .symbols = c("X", "...", "()"), TITLE = "Title unknown",
  PRECISION = NULL, SHOWDECIMALS = 0, info = "info",
  CONTENTS = "unknown", MATRIX = "unknown", SUBJECT_AREA = "unknown",
  SUBJECT_CODE = "unknown", UNITS = "unknown", AGGREGALLOWED = "NO",
  SOURCE = NULL, SURVEY = NULL, REFPERIOD = NULL, NOTE = NULL)

Arguments

.cube

a data cube in data frame format

vars

character vector with the names of the categorical variables of the data cube

measure_vars

character vector with the names of the columns that contain the numeric estimates

measure_name

character string with the name to be given to the 'measure' column

.symbols

character vector with the 'special' symbols for 2 and 3 dots in the px file

TITLE

title of the data cube (default: "Title unknown")

PRECISION

character vector with in the form c("measure_name", "measure") if a certain measure has to be shown with decimals values (default = NULL). Experimental

SHOWDECIMALS

default number of decimals to show (default = 0)

info

name of the column with information on how missing values have to be treated (default: "info")

CONTENTS

character vector of length one with a short description of the content (default = "unknown")

MATRIX

name of the 'data' (default = "unknown")

SUBJECT_AREA

name of the subject area (default = "unknown")

SUBJECT_CODE

subject area code (default = "unknown")

UNITS

unit text (default = "unknown")

AGGREGALLOWED

if the contents can or cannot be aggregated ("YES" or "NO", default = "NO")

SOURCE

the organization responsible for the statistics (default = NULL)

SURVEY

name of the survey (default = NULL)

REFPERIOD

periods of the statistics (default = NULL)

NOTE

character vector with one or more notes. Every element of the character vector will be a row of notes (default = NULL)

Examples

data(c09C)
str(c09C)

# The categorical variables of the data cube are the first 4 columns,
# while the columns from 5 to 10 contain the numeric estimates
c09C_px <- to_px(.cube = c09C, 
                 vars = colnames(c09C)[1:4], 
                 measure_vars = colnames(c09C)[5:10],
                 measure_name = "misura")
                 
head(c09C_px, n = 20)
# c09_px is a character vector where every element is the equivalent of a
# row of a px file. It can be exported in a px file for example with 
# writeLines
## Not run: 
writeLines(c09C_px, con = "c09C_px.px")

## End(Not run)
                 
# to_px2 considers 2 types of 'special' data (missing or other). This information
# is retrieved from the 'info' column of the data cube.
table(c09C$info)
c09C_px2 <- to_px2(.cube = c09C, 
                 vars = colnames(c09C)[1:4], 
                 measure_vars = colnames(c09C)[5:10],
                 measure_name = "misura")
                 
head(c09C_px2, n = 50)

# to_px2 considers 2 types of 'special' data (missing or other). This information
# is retrieved from the 'info' column of the data cube.
table(c09C$info)
c09C_px2 <- to_px2(.cube = c09C, 
                 vars = colnames(c09C)[1:4], 
                 measure_vars = colnames(c09C)[5:10],
                 measure_name = "misura")
                 
head(c09C_px2, n = 50)


gibonet/df2px documentation built on Jan. 13, 2024, 4:12 a.m.