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

Adams, Jean jvadams at usgs.gov
Mon Nov 9 18:19:38 CET 2015


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 via R-help <
r-help at r-project.org> wrote:

> 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 can I do this? I would really appreciate a solution.
> Regards,
> Harun
> --
>
> <mailto:mhrashidbau at yahoo.com>
> <mailto:mhrashidbau at yahoo.com>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list