Re: [R-sig-Geo] Binding columns of pixel values

2021-09-09 Thread Ben Tupper
Hi,

In general you won't be happy with column (or row) binding if you are
starting out with vectors of varying lengths.  That's cbind and rbind
are what I call rectangle-centric.  They want to produce rectangular
data, like matrices and data.frames.  How do they make a rectangle
from 6 vectors of varying lengths?

You don't say but I suspect that you are using either the raster or
terra packages.  Are you extracting different points from each of the
six layers?  If that is the case you could make a single long table of
the extracted values...

eA <- data.frame(name = "A", value = extract(rasterA, xyA)
eB <- data.frame(name = "B", value = extract(rasterB, xyB)
 ...

r <- do.call(rbind, list(eA, eB, ...))


I'm not sure if this is valuable to you or not, but below is an
example of a multilayer SpatRaster.  It won't work if your 6 raster
layers have different sizes and extents.  A set of 3 points are
extracted (one row per point) from the three layers.

f <- system.file("ex/meuse.tif", package="terra")
r <- rast(f)
r <- c(r, r*10, r*100)
names(r) <- LETTERS[1:3]

xy <- cbind(179000, 33)
xy <- rbind(xy-100, xy, xy+1000)
extract(r, xy)
#AB C
#1 378 3780 37800
#2 251 2510 25100
#3 208 2080 20800

Ben


On Thu, Sep 9, 2021 at 12:52 PM Enoch Gyamfi Ampadu  wrote:
>
> Dear List,
>
> I hope you are all well. Please I did an extraction of pixel values for 6
> land cover classes using *extract()*. Now I want to bind them into a
> single *data
> frame* but it is not working due to different lengths of columns. I have
> tried some *cbind* and at some point *rbind* but have still not been
> successful. I will be glad if anyone could assist me with an approach to
> use to bind the columns.
>
> Best regards,
>
> Enoch.
>
> --
> *Enoch Gyamfi - Ampadu, PhD*
>
> *FIDEP Foundation*
>
> *Spiritan University, *
>
> *S05, Ejisu, AR, Ghana*
>
> *Phone: +233 264308887 / +233 593630608*
>
> *email: egamp...@gmail.com *
>
>
> *skype: enoch.ampadu*
> *The highest evidence of nobility is self-control*.
>
> *A simple act of kindness creates an endless ripple*.
>
> [[alternative HTML version deleted]]
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Ben Tupper (he/him)
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Binding columns of pixel values

2021-09-09 Thread Enoch Gyamfi Ampadu
Dear List,

I hope you are all well. Please I did an extraction of pixel values for 6
land cover classes using *extract()*. Now I want to bind them into a
single *data
frame* but it is not working due to different lengths of columns. I have
tried some *cbind* and at some point *rbind* but have still not been
successful. I will be glad if anyone could assist me with an approach to
use to bind the columns.

Best regards,

Enoch.

-- 
*Enoch Gyamfi - Ampadu, PhD*

*FIDEP Foundation*

*Spiritan University, *

*S05, Ejisu, AR, Ghana*

*Phone: +233 264308887 / +233 593630608*

*email: egamp...@gmail.com *


*skype: enoch.ampadu*
*The highest evidence of nobility is self-control*.

*A simple act of kindness creates an endless ripple*.

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo