[R] Reduce(paste, x) question

arun smartpink111 at yahoo.com
Thu Nov 1 20:43:05 CET 2012


HI,

Try this:
I am not sure about the use of paste() here.
To get the output from x:    
sapply(x,function(x) x)
     [,1] [,2]
[1,] "A"  "K" 
[2,] "B"  "L" 
[3,] "C"  "M" 
[4,] "D"  "N" 
[5,] "E"  "O"

If you want to get the result from:
 res<-Reduce(paste, x)
 do.call(rbind,strsplit(res," "))
#     [,1] [,2]
#[1,] "A"  "K" 
#[2,] "B"  "L" 
#[3,] "C"  "M" 
#[4,] "D"  "N" 
#[5,] "E"  "O" 


A.K.




----- Original Message -----
From: mdvaan <mathijsdevaan at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, November 1, 2012 2:47 PM
Subject: [R] Reduce(paste, x) question

I have a question about the Reduce function: 

x <- list()
x[[1]] <- LETTERS[1:5]
x[[2]] <- LETTERS[11:15]
Reduce(paste, x)
[1] "A K" "B L" "C M" "D N" "E O"

How do I get this?:
[1] "A" "K" 
[2] "B" "L"
[3] "C" "M"
[4] "D" "N" 
[5] "E" "O" 

Thanks for your help!



--
View this message in context: http://r.789695.n4.nabble.com/Reduce-paste-x-question-tp4648151.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list