[R] [External] printing with bothe print and cat...
Richard M. Heiberger
rmh @end|ng |rom temp|e@edu
Sat Jul 9 19:01:08 CEST 2022
for(i in 1:5) {
for(j in 1:5) cat(j, " ")
cat(" ", i, "\n")}
print() puts out the [1], so don�t use print().
cat puts out only what you tell it. So if you want a space, you must include the space.
From: R-help <r-help-bounces using r-project.org> on behalf of akshay kulkarni <akshay_e4 using hotmail.com>
Date: Saturday, July 09, 2022 at 12:47
To: R help Mailing list <r-help using r-project.org>
Subject: [External] [R] printing with bothe print and cat...
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 using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Crmh%40temple.edu%7C9409e175bc7045c094c408da61caa961%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637929820309666159%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dKfATg8gOlTDpLqxUFgUSJ1l8%2Bnr3qNakRxPZcFSRdE%3D&reserved=0
PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Crmh%40temple.edu%7C9409e175bc7045c094c408da61caa961%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637929820309666159%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=cFyypcyUFM3eRJWnJ%2FFzUkcc%2FtEjAYl4rJzOkPo29z0%3D&reserved=0
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help
mailing list