nv: Create a named vector from a dataframe, table or vector

Description Usage Arguments Value Author(s) See Also Examples

View source: R/convert.R

Description

The '$' or "[," operators for dataframes and tables do not carry along with them the row names. This function provides a solution for this problem. Additionally this function will accept a vector of values and a corresponding vector of value names–an ideal, in-line way for setting named-vectors as default parameters in new functions.)

Usage

1
nv(x, name)

Arguments

x

The source dataframe, table, vector, or factor

name

The column name you would like to pull out as a named vector. OR the names of the vector (if x is a vector)

Value

a named vector or factor

Author(s)

David Schruth

See Also

vector,name

Examples

1
2
3
4
5
6
7
8
9
## example 1: pulling a row.named vector out of a dataframe
df <- data.frame(a=c(1,2,34,4,5,3,23), b=c('z','x','y','z','x','n','p'))
rownames(df) <- letters[1:nrow(df)]
nv(df,'a')
nv(df,'b')

## example 2: a naming vectors from scratch
nv(c(1,2,3), c('a','b','c'))
nv(df$a, df$b)

caroline documentation built on May 29, 2017, 12:09 p.m.

Related to nv in caroline...