Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create the sequence 1 12 123

Tags:

r

I am doing some R code practice and is wanting to generate some specific sequence.

I want to use the function seq() to generate sequence, which I have tried the following code, but it seems like character is not available in seq()

n <- c(1 : 100)
seq(from = 1, to = n )

I expect the sequence to be 1 1 2 1 2 3 1 2 3 4.... However, this code isn't able to work

like image 870
許弘叡 Avatar asked Mar 04 '23 09:03

許弘叡


1 Answers

In the following way:

sequence(1:100)

sequence works by creating a vector from 1 until the number passed to sequence() Since this function is vectorized, you can insert multiple numbers at once with c(1:100) at get the necessary output.

like image 142
Lennyy Avatar answered Mar 17 '23 03:03

Lennyy