The most obvious difference between sequences in R and Python is Python's use of 0-based indexing:

R:

Python:

Another difference is that in R, but not in Python, one can assign to an index outside the initial range:

In R, but not in regular Python, we can make the increments non-integral values:

We can use numpy to get around this restriction:

It's sometimes more convenient to specify how many numbers we want to obtain (evenly spaced in some interval):

Vectorized operations:

Here are some examples of fancy indexing where we rearrange rows and columns both at the same time:

The naive implementation in Python gives something different than in R (though useful), but the sequential approach works:

R has a few more indexing tricks for which I don't know if there is a Python equivalent:

But here, finally is an example we can do in both:

## No comments:

Post a Comment