[R] Help needed on R output

Adrian Dusa dusa.adrian at gmail.com
Tue May 26 12:24:28 CEST 2009



A simpler solution:
my.string <- c("00000000000000000000000000000000",
"00000000010010010110111111101100",
"00000000100100101101000001011111",
"00000000110111000001000111100011",
"00000001001001010010010100001001",
"00000001011011011111101001101001")

my.string <- paste(my.string, collapse="\",\n\"")

cat(paste("rom_array := (\n\"", my.string, "\")\n", sep=""))

Which produces:
rom_array := (
"00000000000000000000000000000000",
"00000000010010010110111111101100",
"00000000100100101101000001011111",
"00000000110111000001000111100011",
"00000001001001010010010100001001",
"00000001011011011111101001101001")

Search in the archives for character escaping to understand the syntax.

A simple example (notice the gradual additions):
aa <- "010"
cat(aa) # 010

bb <- "\"010"
cat(bb) # "010

cc <- "\"010\""
cat(cc) # "010"

Also read the help for ?paste, and notice the difference between the "sep"
and "collapse" arguments.

Hth,
Adrian



Linlin Yan wrote:
> 
>> t <- c(
> + "00000000000000000000000000000000",
> + "00000000010010010110111111101100",
> + "00000000100100101101000001011111",
> + "00000000110111000001000111100011",
> + "00000001001001010010010100001001",
> + "00000001011011011111101001101001")
>> {
> + cat ('rom_array := (\n');
> + for (i in 1:length(t)) {
> +   cat('"', t[i], '"',
> +     ifelse(i == length(t), '', ',\n'), sep='')
> + };
> + cat(')\n');
> + }
> rom_array := (
> "00000000000000000000000000000000",
> "00000000010010010110111111101100",
> "00000000100100101101000001011111",
> "00000000110111000001000111100011",
> "00000001001001010010010100001001",
> "00000001011011011111101001101001")
>>
> 
> On Tue, May 26, 2009 at 12:30 PM, peng chen <rogerchan2006 at gmail.com>
> wrote:
>> Hi, R experts:
>>
>> I am trying to generate data output in the following format:
>>
>> rom_array := (
>> "00000000000000000000000000000000",
>> "00000000010010010110111111101100",
>> "00000000100100101101000001011111",
>> "00000000110111000001000111100011",
>> "00000001001001010010010100001001",
>> "00000001011011011111101001101001")
>>
>> I have all the necessary data line, however, I am having trouble
>> generating
>> the double quotation marks along with the trailing comma for each line.
>>
>> Anyone can help?
>>
>> Thanks.
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Help-needed-on-R-output-tp23716736p23720449.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list