Learn R Programming

⚠️There's a newer version (1.0.0) of this package.Take me there.

str2str (version 0.2.1)

Convert R Objects from One Structure to Another

Description

Offers a suite of functions for converting to and from (atomic) vectors, matrices, data.frames, and (3D+) arrays as well as lists of these objects. It is an alternative to the base R as..() functions (e.g., as.data.frame.array()) that provides more useful and/or flexible restructuring of R objects. To do so, it only works with common structuring of R objects (e.g., data.frames with only atomic vector columns).

Copy Link

Version

Install

install.packages('str2str')

Monthly Downloads

1,179

Version

0.2.1

License

GPL (>= 2)

Maintainer

David Disabato

Last Published

September 5th, 2021

Functions in str2str (0.2.1)

append<-

Add Elements to Vectors
a2lm

(3D) Array to List of Matrices
all_diff

Test if All Elements are Different
a2ld

3D Array to List of Data-Frames
all_same

Test if All Elements are the Same
abind<-

Add array slices to 3D+ Array `abind<-` adds array slices to arrays as a side effect. It used the function abind in the abind package. The purpose of the function is to replace the need to use ary2 <- abind(ary1, mat1); ary3 <- rbind(ary2, mat2); ary4 <- rbind(ary3, mat3), etc. It allows you to specify the dimension you wish to bind along as well as the dimname you wish to bind after. Unlike `cbind<-`, `rbind<-`, and `append<-`, it does not have overwriting functionality (I could not figure out how to code that); therefore, if value has some dimnames that are the same as those in a, it will NOT overwrite them and simply bind them to a, resulting in duplicate dimnames.
Join

Join (or Merge) a List of Data-frames
a2la

(3D+) Array to List of (3D+) Arrays
a2v

(3D+) Array to (Atomic) Vector
a2d

(3D+) Array to Data-Frame
d2m

Data-Frame to Matrix
d2lv

Data-Frame to List of (Atomic) Vectors
d2d

Data-Frame to Data-Frame (e.g., factors to character vectors)
is.POSIXlt

Test for a POSIXlt object
codes

Integer Codes of Factor Levels
is.avector

Test for an Atomic Vector
d2a

Data-Frame to (3D+) Array or Matrix
ld2d

List of Data-Frames to Data-Frame
inbtw

Elements Inbetween Values Within a (Atomic) Vector
grab

grab extracts the contents of objects in an environment based on their object names as a character vector. The object contents are stored to a list where the names are the object names.
ld2a

List of Data-Frames to a 3D Array
cat0

Concatenate and Print with No Separator
cbind<-

Add Columns to Data Objects
e2l

Environment to List
cbind_fill

Bind DataFrames Along Columns - Filling in Missing Rows with NA
fct2v

Factor to (Atomic) Vector
cbind_fill_matrix

Bind Matrices Along Columns - Filling in Missing Rows with NA
is.empty

Test for Empty Characters
lv2d

List of (atomic) vectors to Data-Frame
lm2v

List of Matrices to (Atomic) Vector
lm2d

List of Matrices to Data-Frame
la2a

List of (3D+) Arrays to (3D+) Array
is.whole

Test for Whole Numbers
ld2v

List of Data-Frames to (Atomic) Vector
is.Date

Test for a Date object
m2lv

Matrix to List of (Atomic) Vectors
is.row.names

Test for `row.names`
is.POSIXct

Test for a POSIXct object
is.names

Test for `names`
lv2v

List of (atomic) Vectors to (atomic) Vector
m2d

Matrix to Data-Frame
is.rownames

Test for `rownames`
ndim

Number of Object Dimensions
nlay

Number of Layers (the Third Dimension)
dimlabels<-

Add Elements to Vectors
dimlabels

Dimension labels (i.e., names of dimnames)
is.cnumeric

Test for Character Numbers
d2v

Data-Frame to (Atomic) Vector
v2fct

Character Vector to (Unordered) Factor
is.colnames

Test for `colnames`
not.row.names

Identify Elements That are Not Row.names
unstack2

Unstack one Set of Variables from Long to Wide
rbind<-

Add Rows to Data Objects `rbind<-` adds rows to data objects as a side effect. The purpose of the function is to replace the need to use dat2 <- rbind(dat1, add1); dat3 <- rbind(dat2, add2); dat4 <- rbind(dat3, add3), etc. For data.frames, it functions similarly to `[<-.data.frame`, but allows you to specify the location of the rows similar to append (vs. c) and overwrite rows with the same rownames. For matrices, it offers more novel functionality since `[<-.matrix` does not exist.
lv2m

List of (atomic) Vectors to Matrix
v2frm

Character Vector to Formula
order.custom

Custom Order Permutation
lm2a

List of Matrices to 3D Array
str2str

Structure to Structure
stack2

Stack one Set of Variables from Wide to Long
m2v

Matrix to (Atomic) Vector
not.colnames

Identify Elements That are Not Colnames
undimlabel

Undimlabel an Object
undimname

Undimname an Object
not.names

Identify Elements That are Not Names
try_fun

Add Try to Function
undim

Undimension an Object
v2lv

(Atomic) Vector to List of (Atomic) Vectors
v2m

(Atomic) Vector to Matrix
not.rownames

Identify Elements That are Not Rownames
v2d

(Atomic) Vector to Data-Frame
t_list

Transpose a List
try_expr

Add Try to Expression
pick

Extract Elements From a (Atomic) Vector
sn

Set a Vector's Names as its Elements sn sets a vector's names as its elements. It is a simple utility function equal to setNames(x, nm = as.character(x)). This is particularly useful when using lapply and you want the return object to have X as its names.