Win xp sp2, R v2.7.1
Hi. If I have two numeric columns in a data frame, I can use the paste
command to combine them into a new column separated by a comma.
c3=paste(c1,c2,sep=',')
gives: 1 1 -> "1,1"
Is there any way I can use a new line (\n) as a separator?
i.e.
1 1 -> 1
1
I tried paste(1,1,'\n') but it only gives "1\n1"
Is there any other command for this? I tried cat but it doesn't work for
columns.
Sorry if its already answered somewhere else, but I couldn't find it.
Thanks.
--
View this message in context:
http://www.nabble.com/paste-command-with-new-line-separator-tp20546923p20546923.html
Sent from the R help mailing list archive at Nabble.com.
Dear slurpy,
Perhaps:
cat('', 1,'\n', 1,'\n')
See ?cat for more information.
HTH,
Jorge
On Mon, Nov 17, 2008 at 3:03 PM, slurpy <sunayan@gmail.com> wrote:
>
> Win xp sp2, R v2.7.1
> Hi. If I have two numeric columns in a data frame, I can use the paste
> command to combine them into a new column separated by a comma.
> c3=paste(c1,c2,sep=',')
> gives: 1 1 -> "1,1"
> Is there any way I can use a new line (\n) as a separator?
> i.e.
> 1 1 -> 1
> 1
> I tried paste(1,1,'\n') but it only gives "1\n1"
> Is there any other command for this? I tried cat but it doesn't work
for
> columns.
> Sorry if its already answered somewhere else, but I couldn't find it.
> Thanks.
> --
> View this message in context:
>
http://www.nabble.com/paste-command-with-new-line-separator-tp20546923p20546923.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>
[[alternative HTML version deleted]]
slurpy <sunayan <at> gmail.com> writes:> > > Win xp sp2, R v2.7.1 > Hi. If I have two numeric columns in a data frame, I can use the paste > command to combine them into a new column separated by a comma. > c3=paste(c1,c2,sep=',') > gives: 1 1 -> "1,1" > Is there any way I can use a new line (\n) as a separator?Yes.> i.e. > 1 1 -> 1 > 1 > I tried paste(1,1,'\n') but it only gives "1\n1"When I use your paste()-command, I get: "1 1 \n" I assume, you used paste(1, 1, sep='\n') with this I get "1\n1" This is completely ok. If you use cat to show the result, "\n" is active: ==========================> cat( paste(1, 1, sep='\n') ) 1 1>>========================== So... it works. Is this what you asked about?> Is there any other command for this? I tried cat but it doesn't work for > columns.Well, did I answered your question, or did I missed the meaning of what you are looking for? Ciao, Oliver