Question: Retrieve specific values from a set of coordinates in R
0
gravatar for ahmad
4.4 years ago by
ahmad0
United States
ahmad0 wrote:

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
ADD COMMENTlink modified 4.4 years ago by Brice Sarver3.1k • written 4.4 years ago by ahmad0
0
gravatar for Brice Sarver
4.4 years ago by
Brice Sarver3.1k
United States
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.

ADD COMMENTlink written 4.4 years ago by Brice Sarver3.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 780 users visited in the last hour