Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

enframe

Converting vectors to data frames, and vice versa


Description

enframe() converts named atomic vectors or lists to one- or two-column data frames. For a list, the result will be a nested tibble with a column of type list. For unnamed vectors, the natural sequence is used as name column.

deframe() converts two-column data frames to a named vector or list, using the first column as name and the second column as value. If the input has only one column, an unnamed vector is returned.

Usage

enframe(x, name = "name", value = "value")

deframe(x)

Arguments

x

An atomic vector (for enframe()) or a data frame with one or two columns (for deframe()).

name, value

Names of the columns that store the names and values. If name is NULL, a one-column tibble is returned; value cannot be NULL.

Value

A tibble with two columns (if name is not NULL, the default) or one column (otherwise).

Examples

enframe(1:3)
enframe(c(a = 5, b = 7))
enframe(list(one = 1, two = 2:3, three = 4:6))
deframe(enframe(3:1))
deframe(tibble(a = 1:3))
deframe(tibble(a = as.list(1:3)))

tibble

Simple Data Frames

v3.1.1
MIT + file LICENSE
Authors
Kirill Müller [aut, cre], Hadley Wickham [aut], Romain Francois [ctb], Jennifer Bryan [ctb], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.