Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to cut a vector in R

  1. Mar 23, 2017 #1
    How do a cut a vector in R? Say I want to split a vector to two parts. One for everything less than 150 and other for everything greater than 150. I tried the cut function but it seems confusing.
     
  2. jcsd
  3. Mar 24, 2017 #2

    Mark44

    Staff: Mentor

    Here are some examples: http://www.endmemo.com/program/R/cut.php
    From the link above:
    Here x is an array of 100 random normal values. (The R code is shown in the link.)
    The cut function breaks the array up into intervals from -5 to 5, with a step size of 1.
    The first few values in the array are
    The first value above lies in the interval (-1, 0]. The second value above lies in the interval (0, 1], and so on.

    As for the question you asked, try something like cut(vec, breaks=0:150:300)

    Here vec is your vector, and the breaks are at 0, 150, and 300.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: How to cut a vector in R
Loading...