Question: Retrieve specific values from a set of coordinates in R
0

Hello,

I have a question that I'm trying to address in the R statistical language. I have a set of coordinates. From these sets of coordinates I want to construct a curve and retrieve the y-values of this curve based on a set of x-values of interest. Is their a way to do that in R? Most importantly from these set of given coordinates, I would like to retrieve y-values for a set x-values of interest.

Thanks for the help,

R • 3.7k views
modified 4.4 years ago by Brice Sarver3.1k • written 4.4 years ago by ahmad0
0
Brice Sarver3.1k wrote:

You need to provide a bit more information about your data for us to answer completely. Here's the general way to do it:

Say you have two vectors, x and y, defined as

x <- c(1, 2, 3, 4, 5)

y <- c(6, 7, 8, 9, 10)

One of the strengths of R is its vector processing; you can apply functions to entire vectors, lists, matrices, etc. So, if these vectors are 1:1, and you want x values less than 3, you would subset positions:

newx <- x[which(x < 3)]

newy <- y[which(x < 3)]

which() returns the indices that satisfy a logical operation. You're now good to plot. Note that this applies to other data structures as well, such as data frames, given that you subset accordingly.

For other clarification, I suggest any of the great introductory R tutorials available online or in print.