Re: [R] Subsetting dataframe by the nearest values of a vector elements

2015-11-10 Thread Harun Rashid via R-help
HI Jean, Here is part of my data. As you can see, I have cross-section point and corresponding elevation of a river. Now I want to select cross-section points by 50m interval. But the real cross-section data might not have exact points say 0, 50, 100,…and so on. Therefore, I need to take points

Re: [R] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread David Winsemius
> On Nov 9, 2015, at 9:19 AM, Adams, Jean wrote: > > Harun, > > Can you give a simple example? > > If your cross_section looked like this > c(144, 179, 214, 39, 284, 109, 74, 4, 249) > and your other vector looked like this > c(0, 50, 100, 150, 200, 250, 300, 350) > what would you want your su

Re: [R] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread jim holtman
Do you want the "closest" or what range it is in? If you want the range, then use 'cut': > x <- c(144, 179, 214, 39, 284, 109, 74, 4, 249) > range <- c(0, 50, 100, 150, 200, 250, 300, 350) > result <- cut(x, breaks = range) > cbind(x, as.character(result)) x [1,] "144" "(100,150]" [2,] "1

Re: [R] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread Adams, Jean
Harun, Can you give a simple example? If your cross_section looked like this c(144, 179, 214, 39, 284, 109, 74, 4, 249) and your other vector looked like this c(0, 50, 100, 150, 200, 250, 300, 350) what would you want your subset to look like? Jean On Mon, Nov 9, 2015 at 7:26 AM, Harun Rashid v

[R] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread Harun Rashid via R-help
Hello, I have a dataset with two columns 1. cross_section (range: 0~635), and 2. elevation. The dataset has more than 100 rows. Now I want to make a subset on the condition that the 'cross_section' column will pick up the nearest cell from another vector (say 0, 50,100,150,200,.,650). How ca