[R] sp package coordinates and gridded problems with as.list()

Paul Hiemstra p.hiemstra at geo.uu.nl
Wed Jan 27 11:45:08 CET 2010


Rhelp wanted wrote:
> Dear All I hope that someone can help.
>
> I am working with sp pakage and akima
> library("akima")
> library(sp)
>
>
>
> imagine lots of different dataframes, of row = 100 columns = 3 of  x and y
> coordinates with z values I will call these data frames for the sake of this
> example akima
>
> akima<-as.list(1:100)
>
> producing 100 dataframes dataframes of the form akima[[i]]
>
> I then wish to interp this list of coordinates:
>
> akima.li<-as.list(1:100)
> for (i in 1:100) akima.li[[i]]<-interp(akima[[i]]$x, akima[[i]]$y, akima
> [[i]]$z)
>
> so now I have 100 akima.li which I then transform into a dataframe of the
> akima.li values
>
> y<-as.list(1:100)
> x<-as.list(1:100)
> z<-as.list(1:100)
>
> for (i in 1:endofrun){
> y[[i]]= rep(akima.li[[i]]$x, each = length(akima.li[[i]]$y))
> x[[i]] = rep(akima.li[[i]]$y, length(akima.li[[i]]$x))
> z[[i]] = as.numeric(akima.li[[i]]$z)
> }
>
> abc<-as.list(1:100)
>
> for (i in 1:endofrun){
> abc[[i]]<- data.frame(x[[i]], y[[i]], z[[i]])
> abc[[i]][is.na(abc[[i]])] <- 0}
>
>
>
> so now I have 100 dataframes with x and y columns and corresponding z values
> and any NAs are now 0.
>
> This is where my problem starts I wish to use sp to state which columns are
> coordinates of the form
>
> for (i in 1:100) coordinates(abc[[i]])= ~x+y
>
> and that all of the dataframes are a grid, such that.
>
> for (i in 1:100)  gridded(abc[[i]]) = TRUE
>
> however I get error messeges such as:
> Error in function (classes, fdef, mtable)  :  unable to find an inherited
> method for function "coordinates<-", for signature "integer"
>   
the input to coordinates should be a data.frame, which abc[[i]] 
obviously isn't. Look at the meuse dataset from the sp-package for a 
sample of how such a data.frame should look like.

cheers,
Paul

ps The r-sig-geo mailing list would be a better place to ask this question
> and I do not know what this means.
>
> I will then want to then go on to overlay such:
>
> datapoint = data.frame(x = 10, y = 20)
> coordinates(datapoint) = ~x+y
> gridded(datapoint)=TRUE
>
> value<-as.list(1:100)
>
> for (i in 1:100)   value [[i]]= abc[[i]]@data[overlay(abc[[i]], datapoint),]
>
> then I will have a list of 100 "value" for each original dataframe
>
> I would be appreciative if someone could tell me how I can allocate
> coordinate and grided systems to an dataframes which are as.list.
>
> I hope that is comprehendable and someone can help. I am very stuck
>
> many thanks Sylvestre
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>   


-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul



More information about the R-help mailing list