paste2: Paste an Unspecified Number Of Text Columns

Description Usage Arguments Value Note See Also Examples

View source: R/paste2.R

Description

paste2 - Paste unspecified columns or a list of vectors together.

colpaste2df - Wrapper for paste2 that returns a dataframe with columns pasted together.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
paste2(multi.columns, sep = ".", handle.na = TRUE, trim = TRUE)

colpaste2df(
  mat,
  combined.columns,
  sep = ".",
  name.sep = "&",
  keep.orig = TRUE,
  ...
)

Arguments

multi.columns

The multiple columns or a list of vectors to paste together.

sep

The character to be used in paste2 to paste the columns.

handle.na

logical. If TRUE returns NA if any column/vector contains a missing value.

trim

logical. If TRUE leading/trailing white space is removed.

mat

A matrix or dataframe.

combined.columns

A list of named vectors of the colnames/indexes of the numeric columns to be pasted. If a vector is unnamed a name will be assigned.

name.sep

The character to be used to paste the column names.

keep.orig

logical. If TRUE the original columns (i.e., combined.columns) will be retained as well.

...

Other arguments passed to paste2.

Value

paste2 - Returns a vector with row-wise elements pasted together.

colpaste2df - Returns a dataframe with pasted columns.

Note

paste differs from paste2 because paste does not allowed an unspecified number of columns to be pasted. This behavior can be convenient for inside of functions when the number of columns being pasted is unknown.

See Also

paste, colsplit2df

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Not run: 
## paste2 examples
v <- rep(list(state.abb[1:8],  month.abb[1:8]) , 5)
n <- sample(5:10, 1)
paste(v[1:n]) #odd looking return
paste2(v[1:n]) 
paste2(v[1:n], sep="|") 
paste2(mtcars[1:10,], sep="|") 
paste(mtcars[1:10,], sep="|") #odd looking return
paste2(CO2[1:10,], sep="|-|") 

## colpaste2df examples
A <- list(
    a = c(1, 2, 3),
    b = qcv(mpg, hp),
    c = c("disp", "am")
)
B <- list(
    c(1, 2, 3),
    new.col = qcv(mpg, hp),
    c("disp", "am")
)
E <- list(
    c(1, 2, 3, 4, 5),
    qcv(mpg, hp),
    c("disp", "am")
)

colpaste2df(head(mtcars), A)
colpaste2df(head(mtcars), B)
colpaste2df(head(mtcars), E)
colpaste2df(head(mtcars), qcv(am, disp, drat), sep ="_", name.sep = "|")
colpaste2df(head(CO2), list(c(1, 2, 3, 4, 5), qcv("conc", "uptake")))

## End(Not run)

trinker/qdap documentation built on Sept. 30, 2020, 6:28 p.m.