[R-sig-Geo] Local_coord

Roger Bivand Roger.Bivand at nhh.no
Mon Jul 21 13:59:25 CEST 2014


On Sun, 20 Jul 2014, Loïc Dutrieux wrote:

> Hello Kátia,
>
> That sounds more like a dataframe manipulation problem; though we can help. 
> See the code below.
>
> library(dplyr)

This may work, but is no help at all in understanding R - dplyr is very 
new, and the %.% or %>% syntax is even newer, and very confusing if the 
assumptions made in chaining the steps together are wrong. If you do 
things step-by-step, you can debug them:

coord <- read.table('Coord_ha_R.txt', header = TRUE, fill = TRUE)
str(coord)
% str() describes structure, so showing factors as such;
% head() doesn't do this - see dplyr documentation
ref_sub_parc_coord <- read.table("ref_sub_parc_coord.txt",
  header = TRUE)
str(ref_sub_parc_coord)
# create index
# ref_sub_parc_coord$Sub_parc <- seq(1,10)
# how does mutate() do this properly?
ref_sub_parc_coord$Sub_parc <- 1:nrow(ref_sub_parc_coord)
# merge two data frames
mm <- merge(ref_sub_parc_coord, coord, by = "Sub_parc")
str(mm)
mm$X_global = mm$X_local + mm$X
mm$Y_global = mm$Y_local + mm$Y
str(mm)

By the way, using dplyr:

all.equal(plots, mm)

Please always try to use standard R functions if possible; things like 
dlpyr may be helpful sometimes, but for working scientists simplicity and 
the ability to debug each step are really much more practical.

Roger


>
> coord <- read.table('Coord_ha_R.txt', header = TRUE, fill = TRUE)
>
> plots <- 'ref_sub_parc_coord.txt' %.%
>  read.table(header = TRUE) %.%
>  mutate(Sub_parc = seq(1,10)) %.%
>  merge(coord, by = 'Sub_parc') %.%
>  mutate(X_global = X_local + X, Y_global = Y_local + Y)
>
>
> Is it more or less what you're aiming at? There are certainly many ways to 
> come to the same result.
> Also you may want to take a look at the dplyr vignette, it's a quick read. 
> (http://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html)
>
> Cheers,
> --
> Loïc Dutrieux
> Wageningen University
>
> On 14-07-20 05:51 PM, Kátia Emidio wrote:
>> Hi there,
>> I need to consolidate my local coordinates gotten in 10x10m sub-plots
>> and to transform them into 100x100m reference. I am doing this by hand
>> in excel... too much time!!
>> I need to sum up a reference measure to subplots measure by creating a
>> loop..
>> The file "Coord_ha_R" has the columns names "ParcelaSub_parcX_localY_local"
>> The reference file (ref_sub_parc_coord) to sum up values to X and Y_
>> local has  the colums name  "sub-parcXY".
>> 
>> For each "XY_local fields in the "coord_ha_R", I need to sum up the
>> respective XY  values in the  "ref_sub_parc_coord" file, considering
>> each sub-parcel.
>> 
>> I'll really apreciate any help, because I have too many plots!!
>> 
>> Thanks
>> --
>> Kátia Emídio da Silva DSc
>> Eng. Florestal
>> Manaus/AM
>> 
>> 
>> 
>> Forestry Engineer
>> Manaus/AM-Brazil
>> 
>> 
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> 
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list