Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - cut a vector

Tags:

r

statistics

I have 503 datapoints and I want to cut away the last 250 to get the 253.

I tried cut ,but these function only gives me groups back...

How can I do that in R?

like image 432
maximus Avatar asked Feb 11 '26 13:02

maximus


1 Answers

In addition to the above answer, you can pass any vector in the square brackets to reduce your vector. The above case you are dropping the last 250 values. You can play around with the values inside the square brackets to get different results

    # Generate some values
    vals <- rnorm(503)

    # Take the last 250
    result <- vals[250:503]

    # Take 1,3,4,7 values
    result <- vals[c(1,3,4,7)]

    # Take alternate values
    result <- vals[seq(1,503,2)]

etc...

like image 180
Avinash Avatar answered Feb 13 '26 09:02

Avinash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!