Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create regular sequence of a certain length, between two limits

Tags:

r

sequence

I am trying to generate python numpy's linspace function's kind of functionality in R. I want to generate equally spaced numbers between a start and an end value, with given length of the sequence.

For example between 10 and 100 if I want to use generate 3 equally spaced numbers. the python code for that would be

linspace(from = 10, to = 100, n = 3)

the output would be : 10 55 100, with difference 45 between each subsequent values.

Any idea how I can achieve this?

like image 524
user47 Avatar asked Sep 13 '25 07:09

user47


1 Answers

As suggested by JasonWang, the solution is to use the length.out argument.

seq(from = 0, to = 1, length.out = 11)

produces 11 equally spaced values between 0 and 1.

See ?seq for help which will have an explanation of how to use the seq function.

like image 136
user47 Avatar answered Sep 15 '25 05:09

user47