You could also loop e.g. (this way you have a bit more control): > long <- c(-81.66,-82.66) > lat <- c(36.21,37.21) > df <- data.frame(lat,long) > df$srtm <- rep(NA, length(df$lat)) > for(i in 1:length(df$srtm)){ + df$srtm[i] <- GNsrtm3(df$lat[i],df$long[i])$srtm3 + } > df lat long srtm 1 36.21 -81.66 990 2 37.21 -82.66 500
But Barry's solution is more straight forward. Tom Hengl -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Barry Rowlingson Sent: Tuesday, November 25, 2008 5:40 PM To: r-sig-geo@stat.math.ethz.ch Subject: Re: [R-sig-Geo] Geonames elevation help 2008/11/25 Michael Denslow <[EMAIL PROTECTED]>: > I am hoping that someone can help me with the GNsrtm3 function in the > Geonames package. I am trying to get elevation values for more than one lat,long stored in a data frame. I am not sure if this function can process more than one request since it is a web query. But since R seems to be able to do anything, I figured I was missing something. > > I am an R novice so any help would be most appreciated. Here is a shortened > example of what I am trying to do. > > library(geonames) > > long <- c(-81.66,-82.66) > lat <- c(36.21,37.21) > df <- data.frame(lat,long) > GNsrtm3(df$lat,df$long) > > # the result below is only for the first set of coordinates > srtm3 lng lat > 1 990 -81.66 36.21 > > I also tried using apply, but it also only seemed to work for the first set > of coordinates. > > Thanks in advance, > Michael > > Maybe you were using apply wrong. With your df, you can do: > df$srtm3=apply(df,1,function(l){GNsrtm3(l[1],l[2])$srtm3}) > df lat long srtm3 1 36.21 -81.66 990 2 37.21 -82.66 500 apply() passes the row of the dataframe as a vector to the function, so I just get the first and last element and call GNsrtm3, and strip off just the result. Oh, make sure I've got the lat-long the right way round. Barry _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo