Skip the for loops: cat(paste( seq(1:5), ? ?, 1:5) ) ? David Sent from my iPhone> On Jul 9, 2022, at 9:47 AM, akshay kulkarni <akshay_e4 at hotmail.com> wrote: > > ?Dear members, > I have the following code: > > testprint <- function() { > > for(i in 1:5) {for(j in 1:5) > {cat(j)} > print(i)} > } > > And the output is: > >> testprint() > 12345[1] 1 > 12345[1] 2 > 12345[1] 3 > 12345[1] 4 > 12345[1] 5 > > Any idea on how to remove the [1] from the output, and give spaces in the cat output? The desired output is: > > 1 2 3 4 5 1 > 1 2 3 4 5 2 > 1 2 3 4 5 3 > 1 2 3 4 5 4 > 1 2 3 4 5 5 > Many thanks in advance..... > > THanking you, > Yours sincreely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
If spaces needed. In first sequences then paste( 1:5, collapse=? ?) Sent from my iPhone> On Jul 9, 2022, at 9:59 AM, David Winsemius <dwinsemius at comcast.net> wrote: > > ?Skip the for loops: > > cat(paste( seq(1:5), ? ?, 1:5) ) > > ? > David > > Sent from my iPhone > >> On Jul 9, 2022, at 9:47 AM, akshay kulkarni <akshay_e4 at hotmail.com> wrote: >> >> ?Dear members, >> I have the following code: >> >> testprint <- function() { >> >> for(i in 1:5) {for(j in 1:5) >> {cat(j)} >> print(i)} >> } >> >> And the output is: >> >>> testprint() >> 12345[1] 1 >> 12345[1] 2 >> 12345[1] 3 >> 12345[1] 4 >> 12345[1] 5 >> >> Any idea on how to remove the [1] from the output, and give spaces in the cat output? The desired output is: >> >> 1 2 3 4 5 1 >> 1 2 3 4 5 2 >> 1 2 3 4 5 3 >> 1 2 3 4 5 4 >> 1 2 3 4 5 5 >> Many thanks in advance..... >> >> THanking you, >> Yours sincreely, >> AKSHAY M KULKARNI >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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.
Dear David, THe code given was a reprex, and unfortunately, I cannot skip the for loops: Its a very big web scraping code. Any alternative? Many thanks in advance... Yours sincrely, AKSHAY M KULKARNI ________________________________ From: David Winsemius <dwinsemius at comcast.net> Sent: Saturday, July 9, 2022 10:28 PM To: akshay kulkarni <akshay_e4 at hotmail.com> Cc: R help Mailing list <r-help at r-project.org> Subject: Re: [R] printing with bothe print and cat... Skip the for loops: cat(paste( seq(1:5), ? ?, 1:5) ) ? David Sent from my iPhone> On Jul 9, 2022, at 9:47 AM, akshay kulkarni <akshay_e4 at hotmail.com> wrote: > > ?Dear members, > I have the following code: > > testprint <- function() { > > for(i in 1:5) {for(j in 1:5) > {cat(j)} > print(i)} > } > > And the output is: > >> testprint() > 12345[1] 1 > 12345[1] 2 > 12345[1] 3 > 12345[1] 4 > 12345[1] 5 > > Any idea on how to remove the [1] from the output, and give spaces in the cat output? The desired output is: > > 1 2 3 4 5 1 > 1 2 3 4 5 2 > 1 2 3 4 5 3 > 1 2 3 4 5 4 > 1 2 3 4 5 5 > Many thanks in advance..... > > THanking you, > Yours sincreely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]