Learn R Programming

rlist (version 0.4.6.2)

list.parse: Convert an object to list with identical structure

Description

This function converts an object representing data to list that represents the same data. For example, a data.frame stored tabular data column-wisely, that is, each column represents a vector of a certain type. list.parse converts a data.frame to a list which represents the data row-wisely so that it can be more convinient to perform other non-tabular data manipulation methods.

Usage

list.parse(x, ...)

# S3 method for default list.parse(x, ...)

# S3 method for matrix list.parse(x, ...)

# S3 method for data.frame list.parse(x, ...)

# S3 method for character list.parse(x, type, ...)

Arguments

x

An object

...

Additional parameters passed to converter function

type

The type of data to parse. Currently json and yaml are supported.

Value

list object representing the data in x

Examples

Run this code
# NOT RUN {
x <- data.frame(a=1:3,type=c('A','C','B'))
list.parse(x)

x <- matrix(rnorm(1000),ncol=5)
rownames(x) <- paste0('item',1:nrow(x))
colnames(x) <- c('a','b','c','d','e')
list.parse(x)

z <- '
a:
  type: x
  class: A
  registered: yes
'
list.parse(z, type='yaml')
# }

Run the code above in your browser using DataLab