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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With