Pasting two vectors with combinations of all vectors' elements
Tag : r , By : user161380
Date : March 29 2020, 07:55 AM
Does that help I have two vectors: , You can use this, but there may be a simpler solution : R> apply(expand.grid(vars, vis), 1, paste, collapse=".")
[1] "SR.1" "PL.1" "SR.2" "PL.2" "SR.3" "PL.3"
as.vector(outer(vars, vis, paste, sep="."))
# [1] "SR.1" "PL.1" "SR.2" "PL.2" "SR.3" "PL.3"

Pasting elements of two vectors alphabetically in r
Date : March 29 2020, 07:55 AM
wish helps you Say I have two vectors: , Here's one approach: apply(cbind(a, b), 1, function(x) paste(sort(x), collapse=" "))
## [1] "george harry" "harry steve" "chris harry" "chris harry"
## [5] "harry steve" "george steve" "chris steve" "george harry"
unlist(Map(function(x, y) paste(sort(c(x, y)), collapse=" "), a, b),,FALSE)
mapply(function(x, y) paste(sort(c(x, y)), collapse=" "), a, b, USE.NAMES = FALSE)

pasting together two vectors with expression command
Tag : r , By : Peter Leung
Date : March 29 2020, 07:55 AM
seems to work fine This is a bit tricky because the expression function expects a list of expressions. Therefore you need to convert the strings returned by paste to a list of unevaluated expressions. One way is like this together < do.call(expression, as.list(parse(text = paste0("italic(", t, ")~", n))))

Creating several new vectors from an original vector with separators
Date : March 29 2020, 07:55 AM
Does that help I'm trying to create several vectors from an original vector. I read some posts but couldn't find something to solve my problem. , This should work: x < c("A", "B", "C", "D;", "1", "2;", "a1", "a2", "a3")
sapply(split(x, c(0, cumsum(grepl(";", x))[length(x)])), function(x) gsub(";", "", x))
$`0`
[1] "A" "B" "C" "D"
$`1`
[1] "1" "2"
$`2`
[1] "a1" "a2" "a3"

I need to split a string based on some character array of separators and not lose these separators in string
Tag : chash , By : Sebastian Gift
Date : March 29 2020, 07:55 AM

