I need help in solving a college homework

This is the the homework: (redacted)

I'm stuck at the beginning, since i do not understand how to make R read numbers like 0,1,2,3... as 00,01,02...
It doesn't affect my evaluation, but i would really appreciate to make a good first impression on my teacher.
Thanks in advance for anyone helping.

Hi, welcome!

Please have a look to our homework policy, homework inspired questions are welcome but they should not include verbatim instructions from your course.

2 Likes

I hope I am not breaking our homework policy; look at the difference between numeric and character variables.

x <- seq(from=0, to=9, by=1)
x <- as.character(x)
x
y <- paste("0", x, sep = "")
y

This converts numbers 0 through 9 to characters, and then pastes a leading zero.

Note that if you have numbers 10 and higher, you may want to convert them to characters to be consistent with 0 through 9.

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.