Retrieve specific values from a set of coordinates in R
1
0
Entering edit mode
9.6 years ago
ahmad • 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 • 6.8k views
ADD COMMENT
0
Entering edit mode
9.6 years ago
Brice Sarver ★ 3.8k

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 COMMENT

Login before adding your answer.

Traffic: 2065 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6