<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to Do a String Join in R</title>
	<atom:link href="http://code.hammerpig.com/string-join.html/feed" rel="self" type="application/rss+xml" />
	<link>http://code.hammerpig.com/string-join.html</link>
	<description>Tips and short tutorials on various programming technologies</description>
	<lastBuildDate>Sun, 05 Feb 2012 17:17:05 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Peter Andrews</title>
		<link>http://code.hammerpig.com/string-join.html/comment-page-1#comment-1101</link>
		<dc:creator>Peter Andrews</dc:creator>
		<pubDate>Sat, 03 Dec 2011 15:45:57 +0000</pubDate>
		<guid isPermaLink="false">http://code.hammerpig.com/?p=545#comment-1101</guid>
		<description>Thanks!

Such a simple thing but I had trouble finding this.</description>
		<content:encoded><![CDATA[<p>Thanks!</p>
<p>Such a simple thing but I had trouble finding this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Franc Brglez</title>
		<link>http://code.hammerpig.com/string-join.html/comment-page-1#comment-314</link>
		<dc:creator>Franc Brglez</dc:creator>
		<pubDate>Wed, 16 Dec 2009 19:36:50 +0000</pubDate>
		<guid isPermaLink="false">http://code.hammerpig.com/?p=545#comment-314</guid>
		<description>Thanks Admin,

Your reply is close but one more step is needed -- recognizing whether or not the returned value is an integer, a hint I got from Prof. Brian Ripley as per
 http://markmail.org/search/list:r-project?q=split+string

In the meantime, I also created and documented two functions, 
  string2vector  and vector2string
that take my R-programming to a level where I am more comfortable. Here they are:

string2vector = function(string=&quot;ch-2 \t sec-7\tex-5&quot;, SS=&quot;\t&quot;, type=&quot;char&quot;)
# This procedure splits a string and assigns substrings to an R-vector.
# The split is controlled by the string separator SS (default value:  SS=&quot;\t&quot;).
# Here we convert  a binary string into a binary vector:
#   let  binS = &quot;10011&quot;  
#   then binV = string2vector(binS, SS=&quot;&quot;, type=&quot;int&quot;)
# Here we convert a string into a vector of substrings:
#   let  strS = &quot;I am done&quot; 
#   then vecS = string2vector(strS, SS=&quot; &quot;, type=&quot;char&quot;)
#
# LIMITATION: The function interprets all substrings either as of type 
#             &quot;int&quot; or &quot;char&quot;.  A function that interprets the type of each
#             substring dynamically may one day be written by an R-guru.
#              
# Franc Brglez, Wed Dec  9 14:19:16 EST 2009
{   
   qlist   = strsplit(string, SS) ; qvector = qlist[[1]]
   n = length(qvector) ; xvector = NULL
   for (i in 1:n) {
       if (type == &quot;int&quot;) {
           tmp = as.integer(qvector[i])
       } else {
           tmp = qvector[i]
       }
	xvector = c(xvector, tmp)
   }
   return(xvector)
} # string2vector

vector2string = function(vector=c(&quot;ch-2&quot;, &quot;sec-7&quot;, &quot;ex-5&quot;), SS=&quot;_&quot;, type=&quot;char&quot;) 
# This procedure converts values from a vector to a concatenation of substrings 
# separated by user-specified string separator SS (default value:  SS=&quot;_&quot;).
# Each substring represents a vector component value, either as a numerical 
# value or as an alphanumeric string. 
# Here we convert a binary vector to a binary string representing an integer:
#   let  binV = c(1,0,0,1)  
#   then strS = vector2string(binV, type=&quot;int&quot;)
# Here we convert a binary vector to string representing a binary sequence:
#   let  binV = c(1,0,0,1)  
#   then seqS = vector2string(binV, SS=&quot; &quot;, type=&quot;char&quot;)
# Here we convert a vector of substrings to colon-separated string:
#   let subsV = c(&quot;I&quot;, &quot;am&quot;, &quot;done&quot;)  
#   then strS = vector2string(subsV, SS=&quot;:&quot;, type=&quot;char&quot;)
#
# LIMITATION: The function interprets all substrings in the vector either as of 
#             type &quot;int&quot; or &quot;char&quot;.  A function that interprets the type of each
#             substring dynamically may one day be written by an R-guru.
#
# Franc Brglez, Wed Dec  9 15:43:59 EST 2009
{   
   if (type == &quot;int&quot;) {
       string = paste(strsplit(paste(vector), &quot; &quot;), collapse=&quot;&quot;)
   } else {
       n = length(vector) ; nm1 = n-1 ; string = &quot;&quot;
       for (i in 1:nm1) {
           tmp    = noquote(vector[i])
           string = paste(string, tmp, SS, sep=&quot;&quot;)
       }
       tmp    = noquote(vector[n])
       string = paste(string, tmp, sep=&quot;&quot;)     
   }
   return(string)
} # vector2string</description>
		<content:encoded><![CDATA[<p>Thanks Admin,</p>
<p>Your reply is close but one more step is needed &#8212; recognizing whether or not the returned value is an integer, a hint I got from Prof. Brian Ripley as per<br />
 <a href="http://markmail.org/search/list:r-project?q=split+string" rel="nofollow">http://markmail.org/search/list:r-project?q=split+string</a></p>
<p>In the meantime, I also created and documented two functions,<br />
  string2vector  and vector2string<br />
that take my R-programming to a level where I am more comfortable. Here they are:</p>
<p>string2vector = function(string=&#8221;ch-2 \t sec-7\tex-5&#8243;, SS=&#8221;\t&#8221;, type=&#8221;char&#8221;)<br />
# This procedure splits a string and assigns substrings to an R-vector.<br />
# The split is controlled by the string separator SS (default value:  SS=&#8221;\t&#8221;).<br />
# Here we convert  a binary string into a binary vector:<br />
#   let  binS = &#8220;10011&#8243;<br />
#   then binV = string2vector(binS, SS=&#8221;", type=&#8221;int&#8221;)<br />
# Here we convert a string into a vector of substrings:<br />
#   let  strS = &#8220;I am done&#8221;<br />
#   then vecS = string2vector(strS, SS=&#8221; &#8220;, type=&#8221;char&#8221;)<br />
#<br />
# LIMITATION: The function interprets all substrings either as of type<br />
#             &#8220;int&#8221; or &#8220;char&#8221;.  A function that interprets the type of each<br />
#             substring dynamically may one day be written by an R-guru.<br />
#<br />
# Franc Brglez, Wed Dec  9 14:19:16 EST 2009<br />
{<br />
   qlist   = strsplit(string, SS) ; qvector = qlist[[1]]<br />
   n = length(qvector) ; xvector = NULL<br />
   for (i in 1:n) {<br />
       if (type == &#8220;int&#8221;) {<br />
           tmp = as.integer(qvector[i])<br />
       } else {<br />
           tmp = qvector[i]<br />
       }<br />
	xvector = c(xvector, tmp)<br />
   }<br />
   return(xvector)<br />
} # string2vector</p>
<p>vector2string = function(vector=c(&#8220;ch-2&#8243;, &#8220;sec-7&#8243;, &#8220;ex-5&#8243;), SS=&#8221;_&#8221;, type=&#8221;char&#8221;)<br />
# This procedure converts values from a vector to a concatenation of substrings<br />
# separated by user-specified string separator SS (default value:  SS=&#8221;_&#8221;).<br />
# Each substring represents a vector component value, either as a numerical<br />
# value or as an alphanumeric string.<br />
# Here we convert a binary vector to a binary string representing an integer:<br />
#   let  binV = c(1,0,0,1)<br />
#   then strS = vector2string(binV, type=&#8221;int&#8221;)<br />
# Here we convert a binary vector to string representing a binary sequence:<br />
#   let  binV = c(1,0,0,1)<br />
#   then seqS = vector2string(binV, SS=&#8221; &#8220;, type=&#8221;char&#8221;)<br />
# Here we convert a vector of substrings to colon-separated string:<br />
#   let subsV = c(&#8220;I&#8221;, &#8220;am&#8221;, &#8220;done&#8221;)<br />
#   then strS = vector2string(subsV, SS=&#8221;:&#8221;, type=&#8221;char&#8221;)<br />
#<br />
# LIMITATION: The function interprets all substrings in the vector either as of<br />
#             type &#8220;int&#8221; or &#8220;char&#8221;.  A function that interprets the type of each<br />
#             substring dynamically may one day be written by an R-guru.<br />
#<br />
# Franc Brglez, Wed Dec  9 15:43:59 EST 2009<br />
{<br />
   if (type == &#8220;int&#8221;) {<br />
       string = paste(strsplit(paste(vector), &#8221; &#8220;), collapse=&#8221;")<br />
   } else {<br />
       n = length(vector) ; nm1 = n-1 ; string = &#8220;&#8221;<br />
       for (i in 1:nm1) {<br />
           tmp    = noquote(vector[i])<br />
           string = paste(string, tmp, SS, sep=&#8221;")<br />
       }<br />
       tmp    = noquote(vector[n])<br />
       string = paste(string, tmp, sep=&#8221;")<br />
   }<br />
   return(string)<br />
} # vector2string</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://code.hammerpig.com/string-join.html/comment-page-1#comment-312</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 14 Dec 2009 20:21:56 +0000</pubDate>
		<guid isPermaLink="false">http://code.hammerpig.com/?p=545#comment-312</guid>
		<description>Hi Franc,

Sorry for the delay. Would the following work for you?

&gt; bar = foo[[1]]
&gt; bar[4]
[1] &quot;1&quot;
&gt; bar[7]
[1] &quot;0&quot;</description>
		<content:encoded><![CDATA[<p>Hi Franc,</p>
<p>Sorry for the delay. Would the following work for you?</p>
<p>&gt; bar = foo[[1]]<br />
&gt; bar[4]<br />
[1] &#8220;1&#8243;<br />
&gt; bar[7]<br />
[1] &#8220;0&#8243;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Franc Brglez</title>
		<link>http://code.hammerpig.com/string-join.html/comment-page-1#comment-304</link>
		<dc:creator>Franc Brglez</dc:creator>
		<pubDate>Tue, 08 Dec 2009 21:04:05 +0000</pubDate>
		<guid isPermaLink="false">http://code.hammerpig.com/?p=545#comment-304</guid>
		<description>paste(x, collapse=&quot;,&quot;) is very useful. Would you have a solution  for the following

&gt; binNum = &quot;1001110&quot;
&gt; foo = noquote(strsplit(binNum, NULL[[1]]))
&gt; foo
[[1]]
[1] 1 0 0 1 1 1 0
&gt; foo[4]
[[1]]
NULL

How would you create, from binNum, a &quot;vector&quot; binSeq = c(1,0,0,1,1,1,0) so that
&gt; binSeq[4]
[1] 1
&gt; binSeq[7]
[1] 0
&gt; 
MANY THANKS -- franc</description>
		<content:encoded><![CDATA[<p>paste(x, collapse=&#8221;,&#8221;) is very useful. Would you have a solution  for the following</p>
<p>&gt; binNum = &#8220;1001110&#8243;<br />
&gt; foo = noquote(strsplit(binNum, NULL[[1]]))<br />
&gt; foo<br />
[[1]]<br />
[1] 1 0 0 1 1 1 0<br />
&gt; foo[4]<br />
[[1]]<br />
NULL</p>
<p>How would you create, from binNum, a &#8220;vector&#8221; binSeq = c(1,0,0,1,1,1,0) so that<br />
&gt; binSeq[4]<br />
[1] 1<br />
&gt; binSeq[7]<br />
[1] 0<br />
&gt;<br />
MANY THANKS &#8212; franc</p>
]]></content:encoded>
	</item>
</channel>
</rss>

