Movatterモバイル変換


[0]ホーム

URL:


Title:Import and Export 'SPSS', 'Stata' and 'SAS' Files
Version:2.5.5
Description:Import foreign statistical formats into R via the embedded 'ReadStat' C library,https://github.com/WizardMac/ReadStat.
License:MIT + file LICENSE
URL:https://haven.tidyverse.org,https://github.com/tidyverse/haven,https://github.com/WizardMac/ReadStat
BugReports:https://github.com/tidyverse/haven/issues
Depends:R (≥ 3.6)
Imports:cli (≥ 3.0.0), forcats (≥ 0.2.0), hms, lifecycle, methods,readr (≥ 0.1.0), rlang (≥ 0.4.0), tibble, tidyselect, vctrs(≥ 0.3.0)
Suggests:covr, crayon, fs, knitr, pillar (≥ 1.4.0), rmarkdown,testthat (≥ 3.0.0), utf8
LinkingTo:cpp11
VignetteBuilder:knitr
Config/Needs/website:tidyverse/tidytemplate
Config/testthat/edition:3
Encoding:UTF-8
RoxygenNote:7.3.2
SystemRequirements:GNU make, zlib: zlib1g-dev (deb), zlib-devel (rpm)
NeedsCompilation:yes
Packaged:2025-05-30 13:09:12 UTC; hadleywickham
Author:Hadley Wickham [aut, cre], Evan Miller [aut, cph] (Author of included ReadStat code), Danny Smith [aut], Posit Software, PBC [cph, fnd]
Maintainer:Hadley Wickham <hadley@posit.co>
Repository:CRAN
Date/Publication:2025-05-30 14:10:02 UTC

haven: Import and Export 'SPSS', 'Stata' and 'SAS' Files

Description

logo

Import foreign statistical formats into R via the embedded 'ReadStat' C library,https://github.com/WizardMac/ReadStat.

Author(s)

Maintainer: Hadley Wickhamhadley@posit.co

Authors:

Other contributors:

See Also

Useful links:


Convert labelled vectors to factors

Description

The base functionas.factor() is not a generic, butforcats::as_factor()is. haven providesas_factor() methods forlabelled() andlabelled_spss() vectors, and data frames. By default, when applied to adata frame, it only affects labelled columns.

Usage

## S3 method for class 'data.frame'as_factor(x, ..., only_labelled = TRUE)## S3 method for class 'haven_labelled'as_factor(  x,  levels = c("default", "labels", "values", "both"),  ordered = FALSE,  ...)## S3 method for class 'labelled'as_factor(  x,  levels = c("default", "labels", "values", "both"),  ordered = FALSE,  ...)

Arguments

x

Object to coerce to a factor.

...

Other arguments passed down to method.

only_labelled

Only apply to labelled columns?

levels

How to create the levels of the generated factor:

  • "default": uses labels where available, otherwise the values.Labels are sorted by value.

  • "both": like "default", but pastes together the level and value

  • "label": use only the labels; unlabelled values becomeNA

  • "values": use only the values

ordered

IfTRUE create an ordered (ordinal) factor, ifFALSE (the default) create a regular (nominal) factor.

Details

Includes methods for both classhaven_labelled andlabelledfor backward compatibility.

Examples

x <- labelled(sample(5, 10, replace = TRUE), c(Bad = 1, Good = 5))# Default method uses values where availableas_factor(x)# You can also extract just the labelsas_factor(x, levels = "labels")# Or just the valuesas_factor(x, levels = "values")# Or combine value and labelas_factor(x, levels = "both")# as_factor() will preserve SPSS missing values from values and rangesy <- labelled_spss(1:10, na_values = c(2, 4), na_range = c(8, 10))as_factor(y)# use zap_missing() first to convert to NAszap_missing(y)as_factor(zap_missing(y))

Create a labelled vector.

Description

A labelled vector is a common data structure in other statisticalenvironments, allowing you to assign text labels to specific values.This class makes it possible to import such labelled vectors in to Rwithout loss of fidelity. This class provides few methods, as Iexpect you'll coerce to a standard R class (e.g. afactor())soon after importing.

Usage

labelled(x = double(), labels = NULL, label = NULL)is.labelled(x)

Arguments

x

A vector to label. Must be either numeric (integer or double) orcharacter.

labels

A named vector orNULL. The vector should be the same typeasx. Unlike factors, labels don't need to be exhaustive: only a fractionof the values might be labelled.

label

A short, human-readable description of the vector.

Examples

s1 <- labelled(c("M", "M", "F"), c(Male = "M", Female = "F"))s2 <- labelled(c(1, 1, 2), c(Male = 1, Female = 2))s3 <- labelled(  c(1, 1, 2),  c(Male = 1, Female = 2),  label = "Assigned sex at birth")# Unfortunately it's not possible to make as.factor work for labelled objects# so instead use as_factor. This works for all types of labelled vectors.as_factor(s1)as_factor(s1, levels = "values")as_factor(s2)# Other statistical software supports multiple types of missing valuess3 <- labelled(  c("M", "M", "F", "X", "N/A"),  c(Male = "M", Female = "F", Refused = "X", "Not applicable" = "N/A"))s3as_factor(s3)# Often when you have a partially labelled numeric vector, labelled values# are special types of missing. Use zap_labels to replace labels with missing# valuesx <- labelled(c(1, 2, 1, 2, 10, 9), c(Unknown = 9, Refused = 10))zap_labels(x)

Labelled vectors for SPSS

Description

This class is only used whenuser_na = TRUE inread_sav(). It is similar to thelabelled() classbut it also models SPSS's user-defined missings, which can be up tothree distinct values, or for numeric vectors a range.

Usage

labelled_spss(  x = double(),  labels = NULL,  na_values = NULL,  na_range = NULL,  label = NULL)

Arguments

x

A vector to label. Must be either numeric (integer or double) orcharacter.

labels

A named vector orNULL. The vector should be the same typeasx. Unlike factors, labels don't need to be exhaustive: only a fractionof the values might be labelled.

na_values

A vector of values that should also be considered as missing.

na_range

A numeric vector of length two giving the (inclusive) extentsof the range. Use-Inf andInf if you want the range to beopen ended.

label

A short, human-readable description of the vector.

Examples

x1 <- labelled_spss(1:10, c(Good = 1, Bad = 8), na_values = c(9, 10))is.na(x1)x2 <- labelled_spss(  1:10,  c(Good = 1, Bad = 8),  na_range = c(9, Inf),  label = "Quality rating")is.na(x2)# Print data and metadatax2

Description

This is a convenience function, useful to explore the variables ofa newly imported dataset.

Usage

print_labels(x, name = NULL)

Arguments

x

A labelled vector

name

The name of the vector (optional)

Examples

s1 <- labelled(c("M", "M", "F"), c(Male = "M", Female = "F"))s2 <- labelled(c(1, 1, 2), c(Male = 1, Female = 2))labelled_df <- tibble::tibble(s1, s2)for (var in names(labelled_df)) {  print_labels(labelled_df[[var]], var)}

Read and write Stata DTA files

Description

Currently haven can read and write logical, integer, numeric, characterand factors. Seelabelled() for how labelled variables inStata are handled in R.

Character vectors will be stored asstrL if any components arestrl_threshold bytes or longer (andversion >= 13); otherwise they willbe stored as the appropriatestr#.

Usage

read_dta(  file,  encoding = NULL,  col_select = NULL,  skip = 0,  n_max = Inf,  .name_repair = "unique")read_stata(  file,  encoding = NULL,  col_select = NULL,  skip = 0,  n_max = Inf,  .name_repair = "unique")write_dta(  data,  path,  version = 14,  label = attr(data, "label"),  strl_threshold = 2045,  adjust_tz = TRUE)

Arguments

file

Either a path to a file, a connection, or literal data(either a single string or a raw vector).

Files ending in.gz,.bz2,.xz, or.zip willbe automatically uncompressed. Files starting with⁠http://⁠,⁠https://⁠,⁠ftp://⁠, or⁠ftps://⁠ will be automaticallydownloaded. Remote gz files can also be automatically downloaded anddecompressed.

Literal data is most useful for examples and tests. To be recognised asliteral data, the input must be either wrapped withI(), be a stringcontaining at least one new line, or be a vector containing at least onestring with a new line.

Using a value ofclipboard() will read from the system clipboard.

encoding

The character encoding used for the file. Generally,only needed for Stata 13 files and earlier. See Encoding sectionfor details.

col_select

One or more selection expressions, like indplyr::select(). Usec() orlist() to use more than one expression.See?dplyr::select for details on available selection options. Only thespecified columns will be read fromdata_file.

skip

Number of lines to skip before reading data.

n_max

Maximum number of lines to read.

.name_repair

Treatment of problematic column names:

  • "minimal": No name repair or checks, beyond basic existence,

  • "unique": Make sure names are unique and not empty,

  • "check_unique": (default value), no name repair, but check they areunique,

  • "universal": Make the namesunique and syntactic

  • a function: apply custom name repair (e.g.,.name_repair = make.namesfor names in the style of base R).

  • A purrr-style anonymous function, seerlang::as_function()

This argument is passed on asrepair tovctrs::vec_as_names().See there for more details on these terms and the strategies usedto enforce them.

data

Data frame to write.

path

Path to a file where the data will be written.

version

File version to use. Supports versions 8-15.

label

Dataset label to use, orNULL. Defaults to the value stored inthe "label" attribute ofdata. Must be <= 80 characters.

strl_threshold

Any character vectors with a maximum length greaterthanstrl_threshold bytes will be stored as a long string (strL) insteadof a standard string (str#) variable ifversion >= 13. This defaults to2045, the maximum length of str# variables. See the Statalong stringdocumentation for more details.

adjust_tz

Stata, SPSS and SAS do not have a concept of time zone,and alldate-time variables are treated as UTC.adjust_tz controlshow the timezone of date-time values is treated when writing.

  • IfTRUE (the default) the timezone of date-time values is ignored, andthey will display the same in R and Stata/SPSS/SAS, e.g."2010-01-01 09:00:00 NZDT" will be written as"2010-01-01 09:00:00".Note that this changes the underlying numeric data, so use caution ifpreserving between-time-point differences is critical.

  • IfFALSE, date-time values are written as the corresponding UTC value,e.g."2010-01-01 09:00:00 NZDT" will be written as"2009-12-31 20:00:00".

Value

A tibble, data frame variant with nice defaults.

Variable labels are stored in the "label" attribute of each variable.It is not printed on the console, but the RStudio viewer will show it.

If a dataset label is defined in Stata, it will stored in the "label"attribute of the tibble.

write_dta() returns the inputdata invisibly.

Character encoding

Prior to Stata 14, files did not declare a text encoding, and thedefault encoding differed across platforms. Ifencoding = NULL,haven assumes the encoding is windows-1252, the text encoding used byStata on Windows. Unfortunately Stata on Mac and Linux use a differentdefault encoding, "latin1". If you encounter an error such as"Unable to convert string to the requested encoding", tryencoding = "latin1"

For Stata 14 and later, you should not need to manually specifyencodingvalue unless the value was incorrectly recorded in the source file.

Examples

path <- system.file("examples", "iris.dta", package = "haven")read_dta(path)tmp <- tempfile(fileext = ".dta")write_dta(mtcars, tmp)read_dta(tmp)read_stata(tmp)

Read SAS files

Description

read_sas() supports both sas7bdat files and the accompanying sas7bcat filesthat SAS uses to record value labels.

Usage

read_sas(  data_file,  catalog_file = NULL,  encoding = NULL,  catalog_encoding = encoding,  col_select = NULL,  skip = 0L,  n_max = Inf,  cols_only = deprecated(),  .name_repair = "unique")

Arguments

data_file,catalog_file

Path to data and catalog files. The files areprocessed withreadr::datasource().

encoding,catalog_encoding

The character encoding used for thedata_file andcatalog_encoding respectively. A value ofNULL uses theencoding specified in the file; use this argument to override it if it isincorrect.

col_select

One or more selection expressions, like indplyr::select(). Usec() orlist() to use more than one expression.See?dplyr::select for details on available selection options. Only thespecified columns will be read fromdata_file.

skip

Number of lines to skip before reading data.

n_max

Maximum number of lines to read.

cols_only

[Deprecated]cols_only is no longersupported; usecol_select instead.

.name_repair

Treatment of problematic column names:

  • "minimal": No name repair or checks, beyond basic existence,

  • "unique": Make sure names are unique and not empty,

  • "check_unique": (default value), no name repair, but check they areunique,

  • "universal": Make the namesunique and syntactic

  • a function: apply custom name repair (e.g.,.name_repair = make.namesfor names in the style of base R).

  • A purrr-style anonymous function, seerlang::as_function()

This argument is passed on asrepair tovctrs::vec_as_names().See there for more details on these terms and the strategies usedto enforce them.

Value

A tibble, data frame variant with nice defaults.

Variable labels are stored in the "label" attribute of each variable. It isnot printed on the console, but the RStudio viewer will show it.

write_sas() returns the inputdata invisibly.

Examples

path <- system.file("examples", "iris.sas7bdat", package = "haven")read_sas(path)

Read and write SPSS files

Description

read_sav() reads both.sav and.zsav files;write_sav() creates.zsav files whencompress = TRUE.read_por() reads.por files.read_spss() uses eitherread_por() orread_sav() based on thefile extension.

Usage

read_sav(  file,  encoding = NULL,  user_na = FALSE,  col_select = NULL,  skip = 0,  n_max = Inf,  .name_repair = "unique")read_por(  file,  user_na = FALSE,  col_select = NULL,  skip = 0,  n_max = Inf,  .name_repair = "unique")write_sav(data, path, compress = c("byte", "none", "zsav"), adjust_tz = TRUE)read_spss(  file,  user_na = FALSE,  col_select = NULL,  skip = 0,  n_max = Inf,  .name_repair = "unique")

Arguments

file

Either a path to a file, a connection, or literal data(either a single string or a raw vector).

Files ending in.gz,.bz2,.xz, or.zip willbe automatically uncompressed. Files starting with⁠http://⁠,⁠https://⁠,⁠ftp://⁠, or⁠ftps://⁠ will be automaticallydownloaded. Remote gz files can also be automatically downloaded anddecompressed.

Literal data is most useful for examples and tests. To be recognised asliteral data, the input must be either wrapped withI(), be a stringcontaining at least one new line, or be a vector containing at least onestring with a new line.

Using a value ofclipboard() will read from the system clipboard.

encoding

The character encoding used for the file. The default,NULL, use the encoding specified in the file, but sometimes thisvalue is incorrect and it is useful to be able to override it.

user_na

IfTRUE variables with user defined missing willbe read intolabelled_spss() objects. IfFALSE, thedefault, user-defined missings will be converted toNA.

col_select

One or more selection expressions, like indplyr::select(). Usec() orlist() to use more than one expression.See?dplyr::select for details on available selection options. Only thespecified columns will be read fromdata_file.

skip

Number of lines to skip before reading data.

n_max

Maximum number of lines to read.

.name_repair

Treatment of problematic column names:

  • "minimal": No name repair or checks, beyond basic existence,

  • "unique": Make sure names are unique and not empty,

  • "check_unique": (default value), no name repair, but check they areunique,

  • "universal": Make the namesunique and syntactic

  • a function: apply custom name repair (e.g.,.name_repair = make.namesfor names in the style of base R).

  • A purrr-style anonymous function, seerlang::as_function()

This argument is passed on asrepair tovctrs::vec_as_names().See there for more details on these terms and the strategies usedto enforce them.

data

Data frame to write.

path

Path to a file where the data will be written.

compress

Compression type to use:

  • "byte": the default, uses byte compression.

  • "none": no compression. This is useful for software that has issues withbyte compressed.sav files (e.g. SAS).

  • "zsav": uses zlib compression and produces a.zsav file. zlibcompression is supported by SPSS version 21.0 and above.

TRUE andFALSE can be used for backwards compatibility, and correspondto the "zsav" and "none" options respectively.

adjust_tz

Stata, SPSS and SAS do not have a concept of time zone,and alldate-time variables are treated as UTC.adjust_tz controlshow the timezone of date-time values is treated when writing.

  • IfTRUE (the default) the timezone of date-time values is ignored, andthey will display the same in R and Stata/SPSS/SAS, e.g."2010-01-01 09:00:00 NZDT" will be written as"2010-01-01 09:00:00".Note that this changes the underlying numeric data, so use caution ifpreserving between-time-point differences is critical.

  • IfFALSE, date-time values are written as the corresponding UTC value,e.g."2010-01-01 09:00:00 NZDT" will be written as"2009-12-31 20:00:00".

Details

Currently haven can read and write logical, integer, numeric, characterand factors. Seelabelled_spss() for how labelled variables inSPSS are handled in R.

Value

A tibble, data frame variant with nice defaults.

Variable labels are stored in the "label" attribute of each variable.It is not printed on the console, but the RStudio viewer will show it.

write_sav() returns the inputdata invisibly.

Examples

path <- system.file("examples", "iris.sav", package = "haven")read_sav(path)tmp <- tempfile(fileext = ".sav")write_sav(mtcars, tmp)read_sav(tmp)

Read and write SAS transport files

Description

The SAS transport format is a open format, as is required for submissionof the data to the FDA.

Usage

read_xpt(  file,  col_select = NULL,  skip = 0,  n_max = Inf,  .name_repair = "unique")write_xpt(  data,  path,  version = 8,  name = NULL,  label = attr(data, "label"),  adjust_tz = TRUE)

Arguments

file

Either a path to a file, a connection, or literal data(either a single string or a raw vector).

Files ending in.gz,.bz2,.xz, or.zip willbe automatically uncompressed. Files starting with⁠http://⁠,⁠https://⁠,⁠ftp://⁠, or⁠ftps://⁠ will be automaticallydownloaded. Remote gz files can also be automatically downloaded anddecompressed.

Literal data is most useful for examples and tests. To be recognised asliteral data, the input must be either wrapped withI(), be a stringcontaining at least one new line, or be a vector containing at least onestring with a new line.

Using a value ofclipboard() will read from the system clipboard.

col_select

One or more selection expressions, like indplyr::select(). Usec() orlist() to use more than one expression.See?dplyr::select for details on available selection options. Only thespecified columns will be read fromdata_file.

skip

Number of lines to skip before reading data.

n_max

Maximum number of lines to read.

.name_repair

Treatment of problematic column names:

  • "minimal": No name repair or checks, beyond basic existence,

  • "unique": Make sure names are unique and not empty,

  • "check_unique": (default value), no name repair, but check they areunique,

  • "universal": Make the namesunique and syntactic

  • a function: apply custom name repair (e.g.,.name_repair = make.namesfor names in the style of base R).

  • A purrr-style anonymous function, seerlang::as_function()

This argument is passed on asrepair tovctrs::vec_as_names().See there for more details on these terms and the strategies usedto enforce them.

data

Data frame to write.

path

Path to a file where the data will be written.

version

Version of transport file specification to use: either 5 or 8.

name

Member name to record in file. Defaults to file name sansextension. Must be <= 8 characters for version 5, and <= 32 charactersfor version 8.

label

Dataset label to use, orNULL. Defaults to the value stored inthe "label" attribute ofdata.

Note that although SAS itself supports dataset labels up to 256 characterslong, dataset labels in SAS transport files must be <= 40 characters.

adjust_tz

Stata, SPSS and SAS do not have a concept of time zone,and alldate-time variables are treated as UTC.adjust_tz controlshow the timezone of date-time values is treated when writing.

  • IfTRUE (the default) the timezone of date-time values is ignored, andthey will display the same in R and Stata/SPSS/SAS, e.g."2010-01-01 09:00:00 NZDT" will be written as"2010-01-01 09:00:00".Note that this changes the underlying numeric data, so use caution ifpreserving between-time-point differences is critical.

  • IfFALSE, date-time values are written as the corresponding UTC value,e.g."2010-01-01 09:00:00 NZDT" will be written as"2009-12-31 20:00:00".

Value

A tibble, data frame variant with nice defaults.

Variable labels are stored in the "label" attribute of each variable.It is not printed on the console, but the RStudio viewer will show it.

If a dataset label is defined, it will be stored in the "label" attributeof the tibble.

write_xpt() returns the inputdata invisibly.

Examples

tmp <- tempfile(fileext = ".xpt")write_xpt(mtcars, tmp)read_xpt(tmp)

"Tagged" missing values

Description

"Tagged" missing values work exactly like regular R missing values exceptthat they store one additional byte of information a tag, which is usuallya letter ("a" to "z"). When by loading a SAS and Stata file, the taggedmissing values always use lower case values.

Usage

tagged_na(...)na_tag(x)is_tagged_na(x, tag = NULL)format_tagged_na(x, digits = getOption("digits"))print_tagged_na(x, digits = getOption("digits"))

Arguments

...

Vectors containing single character. The letter will be used to"tag" the missing value.

x

A numeric vector

tag

IfNULL, will only return true if the tag has this value.

digits

Number of digits to use in string representation

Details

format_tagged_na() andprint_tagged_na() format taggedNA's as NA(a), NA(b), etc.

Examples

x <- c(1:5, tagged_na("a"), tagged_na("z"), NA)# Tagged NA's work identically to regular NAsxis.na(x)# To see that they're special, you need to use na_tag(),# is_tagged_na(), or print_tagged_na():is_tagged_na(x)na_tag(x)print_tagged_na(x)# You can test for specific tagged NAs with the second argumentis_tagged_na(x, "a")# Because the support for tagged's NAs is somewhat tagged on to R,# the left-most NA will tend to be preserved in arithmetic operations.na_tag(tagged_na("a") + tagged_na("z"))

Internal vctrs methods

Description

Internal vctrs methods

Usage

## S3 method for class 'haven_labelled'vec_arith(op, x, y, ...)

Write SAS files

Description

[Deprecated]

write_sas() creates sas7bdat files. Unfortunately the SAS file format iscomplex and undocumented, sowrite_sas() is unreliable and in most casesSAS will not read files that it produces.

write_xpt() writes files in the open SAS transport format, which haslimitations but will be reliably read by SAS.

Usage

write_sas(data, path)

Arguments

data

Data frame to write.

path

Path to file where the data will be written.


Convert empty strings into missing values

Description

Convert empty strings into missing values

Usage

zap_empty(x)

Arguments

x

A character vector

Value

A character vector with empty strings replaced by missing values.

See Also

Other zappers:zap_formats(),zap_label(),zap_labels(),zap_widths()

Examples

x <- c("a", "", "c")zap_empty(x)

Remove format attributes

Description

To provide some mild support for round-tripping variables between Stata/SPSSand R, haven stores variable formats in an attribute:format.stata,format.spss, orformat.sas. If this causes problems for yourcode, you can get rid of them withzap_formats.

Usage

zap_formats(x)

Arguments

x

A vector or data frame.

See Also

Other zappers:zap_empty(),zap_label(),zap_labels(),zap_widths()


Zap variable labels

Description

Removes variable label, leaving unlabelled vectors as is.

Usage

zap_label(x)

Arguments

x

A vector or data frame

See Also

zap_labels() to remove value labels.

Other zappers:zap_empty(),zap_formats(),zap_labels(),zap_widths()

Examples

x1 <- labelled(1:5, c(good = 1, bad = 5), label = "rating")x1zap_label(x1)x2 <- labelled_spss(c(1:4, 9), label = "score", na_values = 9)x2zap_label(x2)# zap_label also works with data framesdf <- tibble::tibble(x1, x2)str(df)str(zap_label(df))

Zap value labels

Description

Removes value labels, leaving unlabelled vectors as is. Use this if youwant to simply drop alllabels from a data frame.

Zapping labels fromlabelled_spss() also removes user-defined missingvalues by default, replacing with standardNAs. Use theuser_na argumentto override this behaviour.

Usage

zap_labels(x, ...)## S3 method for class 'haven_labelled_spss'zap_labels(x, ..., user_na = FALSE)

Arguments

x

A vector or data frame

...

Other arguments passed down to method.

user_na

IfFALSE, the default,zap_labels() will convertlabelled_spss() user-defined missing values toNA. IfTRUE theywill be treated like normal values.

See Also

zap_label() to remove variable labels.

Other zappers:zap_empty(),zap_formats(),zap_label(),zap_widths()

Examples

x1 <- labelled(1:5, c(good = 1, bad = 5))x1zap_labels(x1)x2 <- labelled_spss(c(1:4, 9), c(good = 1, bad = 5), na_values = 9)x2zap_labels(x2)# Keep the user defined missing valueszap_labels(x2, user_na = TRUE)# zap_labels also works with data framesdf <- tibble::tibble(x1, x2)dfzap_labels(df)

Zap special missings to regular R missings

Description

This is useful if you want to convert tagged missing values from SAS orStata, or user-defined missings from SPSS, to regular RNA.

Usage

zap_missing(x)

Arguments

x

A vector or data frame

Examples

x1 <- labelled(  c(1, 5, tagged_na("a", "b")),  c(Unknown = tagged_na("a"), Refused = tagged_na("b")))x1zap_missing(x1)x2 <- labelled_spss(  c(1, 2, 1, 99),  c(missing = 99),  na_value = 99)x2zap_missing(x2)# You can also apply to data framesdf <- tibble::tibble(x1, x2, y = 4:1)dfzap_missing(df)

Remove display width attributes

Description

To provide some mild support for round-tripping variables between SPSSand R, haven stores display widths in an attribute:display_width. If thiscauses problems for your code, you can get rid of them withzap_widths.

Usage

zap_widths(x)

Arguments

x

A vector or data frame.

See Also

Other zappers:zap_empty(),zap_formats(),zap_label(),zap_labels()


[8]ページ先頭

©2009-2025 Movatter.jp