EVOLUTION-MANAGER
Edit File: tstrsplit.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: strsplit and transpose the resulting list efficiently</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for tstrsplit {data.table}"><tr><td>tstrsplit {data.table}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>strsplit and transpose the resulting list efficiently</h2> <h3>Description</h3> <p>This is equivalent to <code>transpose(strsplit(...))</code>. This is a convenient wrapper function to split a column using <code>strsplit</code> and assign the transposed result to individual columns. See examples. </p> <h3>Usage</h3> <pre> tstrsplit(x, ..., fill=NA, type.convert=FALSE, keep, names=FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>The vector to split (and transpose).</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p> All the arguments to be passed to <code><a href="../../base/html/strsplit.html">strsplit</a></code>. </p> </td></tr> <tr valign="top"><td><code>fill</code></td> <td> <p> Default is <code>NA</code>. It is used to fill shorter list elements so as to return each element of the transposed result of equal lengths. </p> </td></tr> <tr valign="top"><td><code>type.convert</code></td> <td> <p><code>TRUE</code> calls <code><a href="../../utils/html/type.convert.html">type.convert</a></code> with <code>as.is=TRUE</code> on the columns.</p> </td></tr> <tr valign="top"><td><code>keep</code></td> <td> <p>Specify indices corresponding to just those list elements to retain in the transposed result. Default is to return all.</p> </td></tr> <tr valign="top"><td><code>names</code></td> <td> <p><code>TRUE</code> auto names the list with <code>V1, V2</code> etc. Default (<code>FALSE</code>) is to return an unnamed list.</p> </td></tr> </table> <h3>Details</h3> <p>It internally calls <code>strsplit</code> first, and then <code><a href="transpose.html">transpose</a></code> on the result. </p> <p><code>names</code> argument can be used to return an auto named list, although this argument does not have any effect when used with <code>:=</code>, which requires names to be provided explicitly. It might be useful in other scenarios. </p> <h3>Value</h3> <p>A transposed list after splitting by the pattern provided. </p> <h3>See Also</h3> <p><code><a href="data.table.html">data.table</a></code>, <code><a href="transpose.html">transpose</a></code> </p> <h3>Examples</h3> <pre> x = c("abcde", "ghij", "klmnopq") strsplit(x, "", fixed=TRUE) tstrsplit(x, "", fixed=TRUE) tstrsplit(x, "", fixed=TRUE, fill="<NA>") # using keep to return just 1,3,5 tstrsplit(x, "", fixed=TRUE, keep=c(1,3,5)) # names argument tstrsplit(x, "", fixed=TRUE, keep=c(1,3,5), names=LETTERS[1:3]) DT = data.table(x=c("A/B", "A", "B"), y=1:3) DT[, c("c1") := tstrsplit(x, "/", fixed=TRUE, keep=1L)][] DT[, c("c1", "c2") := tstrsplit(x, "/", fixed=TRUE)][] </pre> <hr /><div style="text-align: center;">[Package <em>data.table</em> version 1.14.4 <a href="00Index.html">Index</a>]</div> </body></html>