<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I preface this by stating that I'm very much a Rcpp beginner who is comfortable in R but I've never before used C++. I'm working through the Rcpp documentation but haven't been able to answer my question.<div><br></div><div>I've written an Rcpp (v0.10.1) function f that takes as input a CharacterMatrix X. X has 20 million rows and 100 columns. For each row of X the function alters certain entries of that row according to rules governed by some other input variables. f returns the updated version of X. This function works as I'd like it to: </div><div># a toy example with nrow = 2, ncol = 2</div><div>> X <- matrix('A', ncol = 2, nrow = 2)</div><div>> X</div><div><div> [,1] [,2]</div><div>[1,] "A" "A" </div><div>[2,] "A" "A" </div></div><div>> X <- f(X, other_input_variables)</div><div>> X</div><div><div> [,1] [,2]</div><div>[1,] "Z" "A" </div><div>[2,] "z" "A" </div></div><div><br></div><div>However, instead of f returning a CharacterMatrix as it currently does, I'd like to return a CharacterVector Y, where each element of Y is a "collapsed" row of the updated X.<div><br></div><div>I can achieve the desired result in R by using: </div><div>Y <- apply(X=X, MARGIN = 1, FUN = function(x){paste0(x, collapse = '')}) </div><div><div>> Y</div><div>[1] "ZA" "zA"</div></div><div><br></div><div>but I wondered whether this "joining" is likely to be more efficiently performed within my function f? If so, how do I join the 100 individual character entries of a row of the CharacterMatrix X into a single string that will then comprise an element of the returned CharacterVector Y?</div><div><br></div><div>Many thanks,</div><div>Pete<br><div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">--------------------------------</font></div></div><div>Peter Hickey,</div><div>PhD Student/Research Assistant,</div><div>Bioinformatics Division,</div><div>Walter and Eliza Hall Institute of Medical Research,</div><div>1G Royal Parade, Parkville, Vic 3052, Australia.</div><div>Ph: +613 9345 2324</div><div><br></div><div><a href="mailto:hickey@wehi.edu.au">hickey@wehi.edu.au</a></div><div><a href="http://www.wehi.edu.au">http://www.wehi.edu.au</a></div></span></div></span></div></div></div>
</div>
<br></div></div><br clear="both">
______________________________________________________________________<BR>
The information in this email is confidential and intended solely for the addressee.<BR>
You must not disclose, forward, print or use it without the permission of the sender.<BR>
______________________________________________________________________<BR>
</body></html>