display a range from 1 to 10 in r

To display a range from 1 to 10 in R, you can use the : operator to create a sequence of numbers:

main.r
1:10
5 chars
2 lines

This will create a vector with all the integers from 1 to 10. To print this vector, simply enter its name at the console:

main.r
my_range <- 1:10
my_range
26 chars
3 lines

This will output the following:

main.r
[1]  1  2  3  4  5  6  7  8  9 10
34 chars
2 lines

You can also use the seq() function to create a sequence of numbers:

main.r
seq(from = 1, to = 10)
23 chars
2 lines

This will create a vector with all the integers from 1 to 10. To print this vector, simply enter its name at the console:

main.r
my_range <- seq(from = 1, to = 10)
my_range
44 chars
3 lines

This will output the same as the previous example:

main.r
[1]  1  2  3  4  5  6  7  8  9 10
34 chars
2 lines

gistlibby LogSnag