1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to search a data frame by x and y cords in R

  1. Jul 3, 2013 #1
    Hi Readers,

    I seem to have hit an elementary snag while fiddling in R...

    i have a 5x5m surface interpolated at intervals of 0.01... giving 250,000 squares in my grid. i have roughly 20-30 xy cords where i want to retrieve the z value out of the data frame. does anyone know how to search an x y z data frame using the x and y cord?


    okay so ive figured it out using subset....

    but the problem is out of the 250000 rows in the dataframe i want my 20-30 extracted. but the x and y values for the points i want extracted are stored as vectors.. so i need to figure out how to apply subset using vectors.

    by doing

    row<-subset(dataframe, x==1.05 & y==0.25)
    that retrieves the correct row with those x and y values...

    but say i have vectors of equal length for the x and y values i want stored in xt and yt then doing this

    row<-subset(dataframe, x==xt & y==yt)

    results in

    [1] x y Height
    <0 rows> (or 0-length row.names)

    Is there a way i can apply subsetting using vectors for the x and y values i want to extract?


    thanks
     
    Last edited: Jul 3, 2013
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?