Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Merge two lists into single list containing single character vectors R

$
0
0

Okay I'm stumped, I know there are answers about merging lists, and my attempt builds on those answers, but they don't return a single char vector. I have a function that merges lists but the values are separate character vectors:

I dont want the characters as separate strings

csc.list <- mapply(c, rep("CSC", 16), c(1:16), SIMPLIFY=FALSE)

$CSC
[1] "CSC""1"
$CSC
[1] "CSC""2"
...

I don't know how to combine the characters in rows with a wierd heading

csc.list <- mapply(unlist, c(mapply(c, rep("CSC", 16), c(1:16), SIMPLIFY=FALSE)))

CSC   CSC   CSC   CSC   CSC   ...
[1,] "CSC""CSC""CSC""CSC""CSC" ...
[2,] "1""2""3""4""5"   ...

Desired Result of two merged lists

c("CSC 1", "CSC 2", "CSC 3", "CSC 4", "CSC 5", ... , "CSC 16")

[1] "CSC 1""CSC 2""CSC 3""CSC 4""CSC 5" ... "CSC 16"

Bonus if your answer scales to merging more than two, i.e. n lists into single vector of merged characters:

csc.list <- mapply(c, rep("CSC", 16), c(1:16), rep(".R", 16), SIMPLIFY=FALSE)
lalalala <- f(csc.list)

Desired result of three merged lists

[1] "CSC 1.R""CSC 2.R" ...

cat
(source: placekitten.com)


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>