An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090525/44014398/attachment-0001.pl>
Help needed on R output
11 messages · peng chen, Linlin Yan, Menezes, Ian +5 more
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.
Hello I'm unable to get R to connect to the internet at work and I'm guessing its because of our proxy server. Is there any way to change how R connects to the internet? How do I provide it the proxy address? Thank you Ian Confidential: This electronic message and all contents contain information from Syntel, Inc. which may be privileged, confidential or otherwise protected from disclosure. The information is intended to be for the addressee only. If you are not the addressee, any disclosure, copy, distribution or use of the contents of this message is prohibited. If you have received this electronic message in error, please notify the sender immediately and destroy the original message and all copies.
Stefan, Thanks for the response I'm using the GUI version of R in Windows. I usually just click the R icon on my desktop, so Im not sure how I would use the --internet2 option? Ian Menezes -----Original Message----- From: Stefan Grosse [mailto:singularitaet at gmx.net] Sent: Tuesday, May 26, 2009 1:39 PM To: Menezes, Ian Cc: r-help at r-project.org Subject: Re: [R] How R connects to the internet On Tue, 26 May 2009 12:52:16 +0530 "Menezes, Ian"
<Ian_Menezes at Syntelinc.com> wrote:
MI> I'm unable to get R to connect to the internet at work and I'm MI> guessing its because of our proxy server. Is there any way to MI> change how R connects to the internet? How do I provide it the MI> proxy address? You haven't told which operating system you use. For windows there is the option --internet2 for the Rgui.exe that uses the proxy settings of the explorer. hth Stefan Confidential: This electronic message and all contents contain information from Syntel, Inc. which may be privileged, confidential or otherwise protected from disclosure. The information is intended to be for the addressee only. If you are not the addressee, any disclosure, copy, distribution or use of the contents of this message is prohibited. If you have received this electronic message in error, please notify the sender immediately and destroy the original message and all copies. Confidential: This electronic message and all contents contain information from Syntel, Inc. which may be privileged, confidential or otherwise protected from disclosure. The information is intended to be for the addressee only. If you are not the addressee, any disclosure, copy, distribution or use of the contents of this message is prohibited. If you have received this electronic message in error, please notify the sender immediately and destroy the original message and all copies.
On Tue, 26 May 2009 12:52:16 +0530 "Menezes, Ian"
<Ian_Menezes at Syntelinc.com> wrote:
MI> I'm unable to get R to connect to the internet at work and I'm MI> guessing its because of our proxy server. Is there any way to MI> change how R connects to the internet? How do I provide it the MI> proxy address? You haven't told which operating system you use. For windows there is the option --internet2 for the Rgui.exe that uses the proxy settings of the explorer. hth Stefan
peng chen 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.
Hi Peng and others,
I assumed that you wanted to generate that (Pascal?) expression and you
have a character or binary numeric vector of the six elements. Say that
vector is named "binaryvector".
cat("rom_array := (\n")
ends<-c(rep("\",\n",5),"\")\n")
for(i in 1:length(binaryvector))
cat("\"",binaryvector[i],ends[i],sep="")
should do what you want. However, I have two questions:
1) Why does cat put a newline at the end of a call with a sep argument
with a newline in it? It doesn't put the sep argument after the last
element of the vector, even though the help page says that it does.
2) The help page reads:
sep a character vector of strings to append after each element.
but cat clearly uses only the first string of the vector. Am I reading
this wrongly?
Jim
Menezes, Ian wrote:
Stefan, Thanks for the response I'm using the GUI version of R in Windows. I usually just click the R icon on my desktop, so Im not sure how I would use the --internet2 option?
You can edit the shortcut (right click and follow the menus), or install R with that option. Duncan Murdoch
Ian Menezes -----Original Message----- From: Stefan Grosse [mailto:singularitaet at gmx.net] Sent: Tuesday, May 26, 2009 1:39 PM To: Menezes, Ian Cc: r-help at r-project.org Subject: Re: [R] How R connects to the internet On Tue, 26 May 2009 12:52:16 +0530 "Menezes, Ian" <Ian_Menezes at Syntelinc.com> wrote: MI> I'm unable to get R to connect to the internet at work and I'm MI> guessing its because of our proxy server. Is there any way to MI> change how R connects to the internet? How do I provide it the MI> proxy address? You haven't told which operating system you use. For windows there is the option --internet2 for the Rgui.exe that uses the proxy settings of the explorer. hth Stefan Confidential: This electronic message and all contents contain information from Syntel, Inc. which may be privileged, confidential or otherwise protected from disclosure. The information is intended to be for the addressee only. If you are not the addressee, any disclosure, copy, distribution or use of the contents of this message is prohibited. If you have received this electronic message in error, please notify the sender immediately and destroy the original message and all copies. Confidential: This electronic message and all contents contain information from Syntel, Inc. which may be privileged, confidential or otherwise protected from disclosure. The information is intended to be for the addressee only. If you are not the addressee, any disclosure, copy, distribution or use of the contents of this message is prohibited. If you have received this electronic message in error, please notify the sender immediately and destroy the original message and all copies.
______________________________________________ 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.
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090526/80f2f6ee/attachment-0001.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090526/4deea31b/attachment-0001.pl>
Did you mean this:
write.table(t, eol=",\n", row.names=FALSE, col.names=FALSE)
"00000000000000000000000000000000", "00000000010010010110111111101100", "00000000100100101101000001011111", "00000000110111000001000111100011", "00000001001001010010010100001001", "00000001011011011111101001101001", Try ?write.table to get the detail of the function please.
On Tue, May 26, 2009 at 9:33 PM, peng chen <rogerchan2006 at gmail.com> wrote:
Thanks. I am sorry that I did not clearly put my question. I need to output the array like ?t <- c( + "00000000000000000000000000000000", + "00000000010010010110111111101100", + "00000000100100101101000001011111", + "00000000110111000001000111100011", + "00000001001001010010010100001001", + "00000001011011011111101001101001") to a datafile(e.g., .txt file) where each line is for a binary number in this format: "00000000000000000000000000000000", "00000000010010010110111111101100", .... I was trying to use R-function write.table, however, I wasn't able to get the trailing comma for each line(although I can get the double quotation marks). Thanks.