Manipulate extract output

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Manipulate extract output

jm3389
Dear All,

I have been struggling to extract individual pixel values from within a set of polygons.

Mbola.shp <- readOGR(dsn="C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola", "MBSubplot1LULC")
SMA <- raster("C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola/SMA-clipped.img")

X <- extract(SMA, Mbola.shp)

then when I display X I obtain a list:

>X
[[1]]
 [1] 0.08505697 0.11521957 0.07027940 0.07027940 0.10559745 0.10363697 0.09353689
 [8] 0.09353689 0.09673717 0.12536806 0.15696177 0.09306118 0.09353689 0.09673717
[15] 0.09306118 0.09306118 0.09669495

[[2]]
 [1]  0.02609529  0.02609529  0.02996226 -0.00057072  0.02159369  0.02159369
 [7]  0.04489277  0.02804214  0.02835380  0.06462935  0.06462935  0.02266412
[13]  0.03684234  0.02083779  0.07917891  0.05502048  0.03577228

[[3]]
 [1] 0.08705948 0.08705948 0.08622552 0.05902963 0.05902963 0.03294581 0.08919024
 [8] 0.10308155 0.10308155 0.04357137 0.06129387 0.18882106 0.15271443 0.15271443
[15] 0.07749587 0.23532785 0.23532785

[[4]]
 [1] 0.09554891 0.09314694 0.13511878 0.12017184 0.12056647 0.10497463 0.19552167
 [8] 0.19496135 0.10160323 0.09736327 0.12032449 0.18401594 0.13698930 0.09173016
[15] 0.11627619 0.13992140

[[5]]
 [1] 0.08130399 0.12848020 0.15129283 0.06018241 0.06018241 0.12764616 0.15831620
 [8] 0.16025396 0.07245398 0.07245398 0.08861573 0.15831620 0.16025396 0.07245398
[15] 0.08861573 0.10879661

[[6]]
 [1] 0.01403566 0.05509807 0.06573696 0.07086041 0.05806389 0.08060271 0.04586258
 [8] 0.04270630 0.07691538 0.06859619 0.08897498 0.06756449 0.04492125 0.04651234
[15] 0.04652581 0.08224432 0.04266668 0.05377325

[[7]]
 [1] 0.19860968 0.13489768 0.11530623 0.11530623 0.12832202 0.18902805 0.09427368
 [8] 0.08301217 0.08301217 0.11991798 0.18725793 0.19014162 0.14259814 0.14259814
[15] 0.08376002 0.18725793 0.14259814 0.14259814 0.08376002

[[8]]
 [1]  0.06091007  0.06091007  0.05323072  0.03962127  0.04709431  0.04709431
 [7]  0.05578892  0.06078413  0.03223819  0.02318165  0.02318165  0.04193906
[13]  0.04568461 -0.01365644  0.01866432  0.01866432  0.04833658  0.04675072
[19]  0.04113418  0.04113418  0.03635887


I would like to reshape the list like that:

Pixel value  | Polygon
0.08505697     [[1]]
0.11521957     [[1]]
0.07027940     [[1]]
0.07027940     [[1]]
0.10559745     [[1]]
...

I have tried stack, and the reshape package but haven't been able to manipulate the list.
I am sure it's a very simple function but I've been searching the web for days now and nothing really works.

Any suggestion?
Thanks
Joseph
Reply | Threaded
Open this post in threaded view
|

Re: Manipulate extract output

Gustavo Carvalho
Dear Joseph,

Could you please try this?

names(X) <- 1:length(X)
stack(X)

Gustavo.

On Sun, Apr 24, 2011 at 11:55 AM, jm3389 <[hidden email]> wrote:

> Dear All,
>
> I have been struggling to extract individual pixel values from within a set
> of polygons.
>
> Mbola.shp <- readOGR(dsn="C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola",
> "MBSubplot1LULC")
> SMA <- raster("C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola/SMA-clipped.img")
>
> X <- extract(SMA, Mbola.shp)
>
> then when I display X I obtain a list:
>
>>X
> [[1]]
>  [1] 0.08505697 0.11521957 0.07027940 0.07027940 0.10559745 0.10363697
> 0.09353689
>  [8] 0.09353689 0.09673717 0.12536806 0.15696177 0.09306118 0.09353689
> 0.09673717
> [15] 0.09306118 0.09306118 0.09669495
>
> [[2]]
>  [1]  0.02609529  0.02609529  0.02996226 -0.00057072  0.02159369  0.02159369
>  [7]  0.04489277  0.02804214  0.02835380  0.06462935  0.06462935  0.02266412
> [13]  0.03684234  0.02083779  0.07917891  0.05502048  0.03577228
>
> [[3]]
>  [1] 0.08705948 0.08705948 0.08622552 0.05902963 0.05902963 0.03294581
> 0.08919024
>  [8] 0.10308155 0.10308155 0.04357137 0.06129387 0.18882106 0.15271443
> 0.15271443
> [15] 0.07749587 0.23532785 0.23532785
>
> [[4]]
>  [1] 0.09554891 0.09314694 0.13511878 0.12017184 0.12056647 0.10497463
> 0.19552167
>  [8] 0.19496135 0.10160323 0.09736327 0.12032449 0.18401594 0.13698930
> 0.09173016
> [15] 0.11627619 0.13992140
>
> [[5]]
>  [1] 0.08130399 0.12848020 0.15129283 0.06018241 0.06018241 0.12764616
> 0.15831620
>  [8] 0.16025396 0.07245398 0.07245398 0.08861573 0.15831620 0.16025396
> 0.07245398
> [15] 0.08861573 0.10879661
>
> [[6]]
>  [1] 0.01403566 0.05509807 0.06573696 0.07086041 0.05806389 0.08060271
> 0.04586258
>  [8] 0.04270630 0.07691538 0.06859619 0.08897498 0.06756449 0.04492125
> 0.04651234
> [15] 0.04652581 0.08224432 0.04266668 0.05377325
>
> [[7]]
>  [1] 0.19860968 0.13489768 0.11530623 0.11530623 0.12832202 0.18902805
> 0.09427368
>  [8] 0.08301217 0.08301217 0.11991798 0.18725793 0.19014162 0.14259814
> 0.14259814
> [15] 0.08376002 0.18725793 0.14259814 0.14259814 0.08376002
>
> [[8]]
>  [1]  0.06091007  0.06091007  0.05323072  0.03962127  0.04709431  0.04709431
>  [7]  0.05578892  0.06078413  0.03223819  0.02318165  0.02318165  0.04193906
> [13]  0.04568461 -0.01365644  0.01866432  0.01866432  0.04833658  0.04675072
> [19]  0.04113418  0.04113418  0.03635887
>
>
> I would like to reshape the list like that:
>
> Pixel value  | Polygon
> 0.08505697     [[1]]
> 0.11521957     [[1]]
> 0.07027940     [[1]]
> 0.07027940     [[1]]
> 0.10559745     [[1]]
> ...
>
> I have tried stack, and the reshape package but haven't been able to
> manipulate the list.
> I am sure it's a very simple function but I've been searching the web for
> days now and nothing really works.
>
> Any suggestion?
> Thanks
> Joseph
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301073.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Manipulate extract output

jm3389
Thanks for the quick response Gustavo.

after names(X) <- 1:length(X) 

I get this:

>X
$`1`
 [1] 0.08505697 0.11521957 0.07027940 0.07027940 0.10559745 0.10363697 0.09353689
 [8] 0.09353689 0.09673717 0.12536806 0.15696177 0.09306118 0.09353689 0.09673717
[15] 0.09306118 0.09306118 0.09669495

$`2`
 [1]  0.02609529  0.02609529  0.02996226 -0.00057072  0.02159369  0.02159369
 [7]  0.04489277  0.02804214  0.02835380  0.06462935  0.06462935  0.02266412
[13]  0.03684234  0.02083779  0.07917891  0.05502048  0.03577228

$`3`
 [1] 0.08705948 0.08705948 0.08622552 0.05902963 0.05902963 0.03294581 0.08919024
 [8] 0.10308155 0.10308155 0.04357137 0.06129387 0.18882106 0.15271443 0.15271443
[15] 0.07749587 0.23532785 0.23532785

And I am able to call individual vectors using this command X$'1', so that's an improvement.

Yet the stack(X) still doesn't work

> stack(X)
Error in .local(x, ...) : 
  Arguments should be Raster* objects or filenames


On Sun, Apr 24, 2011 at 11:15 AM, Gustavo Carvalho [via R-sig-geo] <[hidden email]> wrote:
Dear Joseph,

Could you please try this?

names(X) <- 1:length(X)
stack(X)

Gustavo.

On Sun, Apr 24, 2011 at 11:55 AM, jm3389 <[hidden email]> wrote:

> Dear All,
>
> I have been struggling to extract individual pixel values from within a set
> of polygons.
>
> Mbola.shp <- readOGR(dsn="C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola",
> "MBSubplot1LULC")
> SMA <- raster("C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola/SMA-clipped.img")
>
> X <- extract(SMA, Mbola.shp)
>
> then when I display X I obtain a list:
>
>>X
> [[1]]
>  [1] 0.08505697 0.11521957 0.07027940 0.07027940 0.10559745 0.10363697
> 0.09353689
>  <a href="tel:%5B8%5D%200.09353689" value="+18009353689" target="_blank">[8] 0.09353689 0.09673717 0.12536806 0.15696177 0.09306118 0.09353689
> 0.09673717
> <a href="tel:%5B15%5D%200.09306118" value="+15009306118" target="_blank">[15] 0.09306118 0.09306118 0.09669495
>
> [[2]]
>  [1]  0.02609529  0.02609529  0.02996226 -0.00057072  0.02159369  0.02159369
>  [7]  0.04489277  0.02804214  0.02835380  0.06462935  0.06462935  0.02266412
> [13]  0.03684234  0.02083779  0.07917891  0.05502048  0.03577228
>
> [[3]]
>  [1] 0.08705948 0.08705948 0.08622552 0.05902963 0.05902963 0.03294581
> 0.08919024
>  [8] 0.10308155 0.10308155 0.04357137 0.06129387 0.18882106 0.15271443
> 0.15271443
> <a href="tel:%5B15%5D%200.07749587" value="+15007749587" target="_blank">[15] 0.07749587 0.23532785 0.23532785
>
> [[4]]
>  [1] 0.09554891 0.09314694 0.13511878 0.12017184 0.12056647 0.10497463
> 0.19552167
>  <a href="tel:%5B8%5D%200.19496135" value="+18019496135" target="_blank">[8] 0.19496135 0.10160323 0.09736327 0.12032449 0.18401594 0.13698930
> 0.09173016
> [15] 0.11627619 0.13992140
>
> [[5]]
>  [1] 0.08130399 0.12848020 0.15129283 0.06018241 0.06018241 0.12764616
> 0.15831620
>  <a href="tel:%5B8%5D%200.16025396" value="+18016025396" target="_blank">[8] 0.16025396 0.07245398 0.07245398 0.08861573 0.15831620 0.16025396
> 0.07245398
> <a href="tel:%5B15%5D%200.08861573" value="+15008861573" target="_blank">[15] 0.08861573 0.10879661
>
> [[6]]
>  [1] 0.01403566 0.05509807 0.06573696 0.07086041 0.05806389 0.08060271
> 0.04586258
>  <a href="tel:%5B8%5D%200.04270630" value="+18004270630" target="_blank">[8] 0.04270630 0.07691538 0.06859619 0.08897498 0.06756449 0.04492125
> 0.04651234
> <a href="tel:%5B15%5D%200.04652581" value="+15004652581" target="_blank">[15] 0.04652581 0.08224432 0.04266668 0.05377325
>
> [[7]]
>  [1] 0.19860968 0.13489768 0.11530623 0.11530623 0.12832202 0.18902805
> 0.09427368
>  <a href="tel:%5B8%5D%200.08301217" value="+18008301217" target="_blank">[8] 0.08301217 0.08301217 0.11991798 0.18725793 0.19014162 0.14259814
> 0.14259814
> <a href="tel:%5B15%5D%200.08376002" value="+15008376002" target="_blank">[15] 0.08376002 0.18725793 0.14259814 0.14259814 0.08376002
>
> [[8]]
>  [1]  0.06091007  0.06091007  0.05323072  0.03962127  0.04709431  0.04709431
>  [7]  0.05578892  0.06078413  0.03223819  0.02318165  0.02318165  0.04193906
> [13]  0.04568461 -0.01365644  0.01866432  0.01866432  0.04833658  0.04675072
> [19]  0.04113418  0.04113418  0.03635887
>
>
> I would like to reshape the list like that:
>
> Pixel value  | Polygon
> 0.08505697     [[1]]
> 0.11521957     [[1]]
> 0.07027940     [[1]]
> 0.07027940     [[1]]
> 0.10559745     [[1]]
> ...
>
> I have tried stack, and the reshape package but haven't been able to
> manipulate the list.
> I am sure it's a very simple function but I've been searching the web for
> days now and nothing really works.
>
> Any suggestion?
> Thanks
> Joseph
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301073.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]

If you reply to this email, your message will be added to the discussion below:
http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301092.html
To unsubscribe from Manipulate extract output, click here.

Reply | Threaded
Open this post in threaded view
|

Re: Manipulate extract output

Gustavo Carvalho
utils::stack(X)

On Sun, Apr 24, 2011 at 6:21 PM, jm3389 <[hidden email]> wrote:

> Thanks for the quick response Gustavo.
>
> after names(X) <- 1:length(X)
>
> I get this:
>
>>X
> $`1`
>  [1] 0.08505697 0.11521957 0.07027940 0.07027940 0.10559745 0.10363697
> 0.09353689
>  [8] 0.09353689 0.09673717 0.12536806 0.15696177 0.09306118 0.09353689
> 0.09673717
> [15] 0.09306118 0.09306118 0.09669495
>
> $`2`
>  [1]  0.02609529  0.02609529  0.02996226 -0.00057072  0.02159369  0.02159369
>  [7]  0.04489277  0.02804214  0.02835380  0.06462935  0.06462935  0.02266412
> [13]  0.03684234  0.02083779  0.07917891  0.05502048  0.03577228
>
> $`3`
>  [1] 0.08705948 0.08705948 0.08622552 0.05902963 0.05902963 0.03294581
> 0.08919024
>  [8] 0.10308155 0.10308155 0.04357137 0.06129387 0.18882106 0.15271443
> 0.15271443
> [15] 0.07749587 0.23532785 0.23532785
>
> And I am able to call individual vectors using this command X$'1', so that's
> an improvement.
>
> Yet the stack(X) still doesn't work
>
>> stack(X)
> Error in .local(x, ...) :
>  Arguments should be Raster* objects or filenames
>
>
> On Sun, Apr 24, 2011 at 11:15 AM, Gustavo Carvalho [via R-sig-geo] <
> [hidden email]> wrote:
>
>> Dear Joseph,
>>
>> Could you please try this?
>>
>> names(X) <- 1:length(X)
>> stack(X)
>>
>> Gustavo.
>>
>> On Sun, Apr 24, 2011 at 11:55 AM, jm3389 <[hidden email]<http://user/SendEmail.jtp?type=node&node=6301092&i=0&by-user=t>>
>> wrote:
>>
>> > Dear All,
>> >
>> > I have been struggling to extract individual pixel values from within a
>> set
>> > of polygons.
>> >
>> > Mbola.shp <- readOGR(dsn="C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola",
>> > "MBSubplot1LULC")
>> > SMA <-
>> raster("C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola/SMA-clipped.img")
>> >
>> > X <- extract(SMA, Mbola.shp)
>> >
>> > then when I display X I obtain a list:
>> >
>> >>X
>> > [[1]]
>> >  [1] 0.08505697 0.11521957 0.07027940 0.07027940 0.10559745 0.10363697
>> > 0.09353689
>> >  [8] 0.09353689 0.09673717 0.12536806 0.15696177 0.09306118 0.09353689
>> > 0.09673717
>> > [15] 0.09306118 0.09306118 0.09669495
>> >
>> > [[2]]
>> >  [1]  0.02609529  0.02609529  0.02996226 -0.00057072  0.02159369
>>  0.02159369
>> >  [7]  0.04489277  0.02804214  0.02835380  0.06462935  0.06462935
>>  0.02266412
>> > [13]  0.03684234  0.02083779  0.07917891  0.05502048  0.03577228
>> >
>> > [[3]]
>> >  [1] 0.08705948 0.08705948 0.08622552 0.05902963 0.05902963 0.03294581
>> > 0.08919024
>> >  [8] 0.10308155 0.10308155 0.04357137 0.06129387 0.18882106 0.15271443
>> > 0.15271443
>> > [15] 0.07749587 0.23532785 0.23532785
>> >
>> > [[4]]
>> >  [1] 0.09554891 0.09314694 0.13511878 0.12017184 0.12056647 0.10497463
>> > 0.19552167
>> >  [8] 0.19496135 0.10160323 0.09736327 0.12032449 0.18401594 0.13698930
>> > 0.09173016
>> > [15] 0.11627619 0.13992140
>> >
>> > [[5]]
>> >  [1] 0.08130399 0.12848020 0.15129283 0.06018241 0.06018241 0.12764616
>> > 0.15831620
>> >  [8] 0.16025396 0.07245398 0.07245398 0.08861573 0.15831620 0.16025396
>> > 0.07245398
>> > [15] 0.08861573 0.10879661
>> >
>> > [[6]]
>> >  [1] 0.01403566 0.05509807 0.06573696 0.07086041 0.05806389 0.08060271
>> > 0.04586258
>> >  [8] 0.04270630 0.07691538 0.06859619 0.08897498 0.06756449 0.04492125
>> > 0.04651234
>> > [15] 0.04652581 0.08224432 0.04266668 0.05377325
>> >
>> > [[7]]
>> >  [1] 0.19860968 0.13489768 0.11530623 0.11530623 0.12832202 0.18902805
>> > 0.09427368
>> >  [8] 0.08301217 0.08301217 0.11991798 0.18725793 0.19014162 0.14259814
>> > 0.14259814
>> > [15] 0.08376002 0.18725793 0.14259814 0.14259814 0.08376002
>> >
>> > [[8]]
>> >  [1]  0.06091007  0.06091007  0.05323072  0.03962127  0.04709431
>>  0.04709431
>> >  [7]  0.05578892  0.06078413  0.03223819  0.02318165  0.02318165
>>  0.04193906
>> > [13]  0.04568461 -0.01365644  0.01866432  0.01866432  0.04833658
>>  0.04675072
>> > [19]  0.04113418  0.04113418  0.03635887
>> >
>> >
>> > I would like to reshape the list like that:
>> >
>> > Pixel value  | Polygon
>> > 0.08505697     [[1]]
>> > 0.11521957     [[1]]
>> > 0.07027940     [[1]]
>> > 0.07027940     [[1]]
>> > 0.10559745     [[1]]
>> > ...
>> >
>> > I have tried stack, and the reshape package but haven't been able to
>> > manipulate the list.
>> > I am sure it's a very simple function but I've been searching the web for
>>
>> > days now and nothing really works.
>> >
>> > Any suggestion?
>> > Thanks
>> > Joseph
>> >
>> >
>> > --
>> > View this message in context:
>> http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301073.html<http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301073.html?by-user=t>
>> > Sent from the R-sig-geo mailing list archive at Nabble.com.
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > [hidden email]<http://user/SendEmail.jtp?type=node&node=6301092&i=1&by-user=t>
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]<http://user/SendEmail.jtp?type=node&node=6301092&i=2&by-user=t>
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301092.html
>>  To unsubscribe from Manipulate extract output, click here<
>>
>>
>
>
> --
> View this message in context:
http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301561.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Manipulate extract output

jm3389
My bad forgot to add utils::

it's working ! Thanks a lot Gustavo

>utils::stack(X)
             values       ind
1     0.0850569680   1
2     0.1152195707   1
3     0.0702793971   1
4     0.0702793971   1
5     0.1055974513   1
6     0.1036369652   1
7     0.0935368910   1
8     0.0935368910   1
9     0.0967371687   1
10    0.1253680587   1
11    0.1569617689   1
12    0.0930611789   1
13    0.0935368910   1
14    0.0967371687   1
15    0.0930611789   1
16    0.0930611789   1
17    0.0966949463   1
18    0.0260952916   2
19    0.0260952916   2
20    0.0299622640   2
21   -0.0005707200   2
22    0.0215936881   2

---------------------------------------------------------
Joseph Muhlhausen
Project development researcher | CIESIN
61 Route 9W, PO Box 1000
Palisades, NY 10964 USA | 845-365-8935




On Sun, Apr 24, 2011 at 5:54 PM, Gustavo Carvalho [via R-sig-geo] <[hidden email]> wrote:
utils::stack(X)

On Sun, Apr 24, 2011 at 6:21 PM, jm3389 <[hidden email]> wrote:

> Thanks for the quick response Gustavo.
>
> after names(X) <- 1:length(X)
>
> I get this:
>
>>X
> $`1`
>  [1] 0.08505697 0.11521957 0.07027940 0.07027940 0.10559745 0.10363697
> 0.09353689
>  <a href="tel:%5B8%5D%200.09353689" value="+18009353689" target="_blank">[8] 0.09353689 0.09673717 0.12536806 0.15696177 0.09306118 0.09353689
> 0.09673717
> <a href="tel:%5B15%5D%200.09306118" value="+15009306118" target="_blank">[15] 0.09306118 0.09306118 0.09669495
>
> $`2`
>  [1]  0.02609529  0.02609529  0.02996226 -0.00057072  0.02159369  0.02159369
>  [7]  0.04489277  0.02804214  0.02835380  0.06462935  0.06462935  0.02266412
> [13]  0.03684234  0.02083779  0.07917891  0.05502048  0.03577228
>
> $`3`
>  [1] 0.08705948 0.08705948 0.08622552 0.05902963 0.05902963 0.03294581
> 0.08919024
>  [8] 0.10308155 0.10308155 0.04357137 0.06129387 0.18882106 0.15271443
> 0.15271443
> <a href="tel:%5B15%5D%200.07749587" value="+15007749587" target="_blank">[15] 0.07749587 0.23532785 0.23532785
>
> And I am able to call individual vectors using this command X$'1', so that's
> an improvement.
>
> Yet the stack(X) still doesn't work
>
>> stack(X)
> Error in .local(x, ...) :
>  Arguments should be Raster* objects or filenames
>
>
> On Sun, Apr 24, 2011 at 11:15 AM, Gustavo Carvalho [via R-sig-geo] <
> [hidden email]> wrote:

>
>> Dear Joseph,
>>
>> Could you please try this?
>>
>> names(X) <- 1:length(X)
>> stack(X)
>>
>> Gustavo.
>>
>> On Sun, Apr 24, 2011 at 11:55 AM, jm3389 <[hidden email]<http://user/SendEmail.jtp?type=node&node=6301092&i=0&by-user=t>>
>> wrote:

>>
>> > Dear All,
>> >
>> > I have been struggling to extract individual pixel values from within a
>> set
>> > of polygons.
>> >
>> > Mbola.shp <- readOGR(dsn="C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola",
>> > "MBSubplot1LULC")
>> > SMA <-
>> raster("C:/Users/JOX201S/Desktop/Dropbox/LDSF/Mbola/SMA-clipped.img")
>> >
>> > X <- extract(SMA, Mbola.shp)
>> >
>> > then when I display X I obtain a list:
>> >
>> >>X
>> > [[1]]
>> >  [1] 0.08505697 0.11521957 0.07027940 0.07027940 0.10559745 0.10363697
>> > 0.09353689
>> >  <a href="tel:%5B8%5D%200.09353689" value="+18009353689" target="_blank">[8] 0.09353689 0.09673717 0.12536806 0.15696177 0.09306118 0.09353689
>> > 0.09673717
>> > <a href="tel:%5B15%5D%200.09306118" value="+15009306118" target="_blank">[15] 0.09306118 0.09306118 0.09669495
>> >
>> > [[2]]
>> >  [1]  0.02609529  0.02609529  0.02996226 -0.00057072  0.02159369
>>  0.02159369
>> >  [7]  0.04489277  0.02804214  0.02835380  0.06462935  0.06462935
>>  0.02266412
>> > [13]  0.03684234  0.02083779  0.07917891  0.05502048  0.03577228
>> >
>> > [[3]]
>> >  [1] 0.08705948 0.08705948 0.08622552 0.05902963 0.05902963 0.03294581
>> > 0.08919024
>> >  [8] 0.10308155 0.10308155 0.04357137 0.06129387 0.18882106 0.15271443
>> > 0.15271443
>> > <a href="tel:%5B15%5D%200.07749587" value="+15007749587" target="_blank">[15] 0.07749587 0.23532785 0.23532785
>> >
>> > [[4]]
>> >  [1] 0.09554891 0.09314694 0.13511878 0.12017184 0.12056647 0.10497463
>> > 0.19552167
>> >  <a href="tel:%5B8%5D%200.19496135" value="+18019496135" target="_blank">[8] 0.19496135 0.10160323 0.09736327 0.12032449 0.18401594 0.13698930
>> > 0.09173016
>> > [15] 0.11627619 0.13992140
>> >
>> > [[5]]
>> >  [1] 0.08130399 0.12848020 0.15129283 0.06018241 0.06018241 0.12764616
>> > 0.15831620
>> >  <a href="tel:%5B8%5D%200.16025396" value="+18016025396" target="_blank">[8] 0.16025396 0.07245398 0.07245398 0.08861573 0.15831620 0.16025396
>> > 0.07245398
>> > <a href="tel:%5B15%5D%200.08861573" value="+15008861573" target="_blank">[15] 0.08861573 0.10879661
>> >
>> > [[6]]
>> >  [1] 0.01403566 0.05509807 0.06573696 0.07086041 0.05806389 0.08060271
>> > 0.04586258
>> >  <a href="tel:%5B8%5D%200.04270630" value="+18004270630" target="_blank">[8] 0.04270630 0.07691538 0.06859619 0.08897498 0.06756449 0.04492125
>> > 0.04651234
>> > <a href="tel:%5B15%5D%200.04652581" value="+15004652581" target="_blank">[15] 0.04652581 0.08224432 0.04266668 0.05377325
>> >
>> > [[7]]
>> >  [1] 0.19860968 0.13489768 0.11530623 0.11530623 0.12832202 0.18902805
>> > 0.09427368
>> >  <a href="tel:%5B8%5D%200.08301217" value="+18008301217" target="_blank">[8] 0.08301217 0.08301217 0.11991798 0.18725793 0.19014162 0.14259814
>> > 0.14259814
>> > <a href="tel:%5B15%5D%200.08376002" value="+15008376002" target="_blank">[15] 0.08376002 0.18725793 0.14259814 0.14259814 0.08376002
>> >
>> > [[8]]
>> >  [1]  0.06091007  0.06091007  0.05323072  0.03962127  0.04709431
>>  0.04709431
>> >  [7]  0.05578892  0.06078413  0.03223819  0.02318165  0.02318165
>>  0.04193906
>> > [13]  0.04568461 -0.01365644  0.01866432  0.01866432  0.04833658
>>  0.04675072
>> > [19]  0.04113418  0.04113418  0.03635887
>> >
>> >
>> > I would like to reshape the list like that:
>> >
>> > Pixel value  | Polygon
>> > 0.08505697     [[1]]
>> > 0.11521957     [[1]]
>> > 0.07027940     [[1]]
>> > 0.07027940     [[1]]
>> > 0.10559745     [[1]]
>> > ...
>> >
>> > I have tried stack, and the reshape package but haven't been able to
>> > manipulate the list.
>> > I am sure it's a very simple function but I've been searching the web for
>>
>> > days now and nothing really works.
>> >
>> > Any suggestion?
>> > Thanks
>> > Joseph
>> >
>> >
>> > --
>> > View this message in context:
>> http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301073.html<http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301073.html?by-user=t>

>> > Sent from the R-sig-geo mailing list archive at Nabble.com.
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

>>
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the discussion
>> below:
>>
>>

>>
>>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301561.html

> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



If you reply to this email, your message will be added to the discussion below:
http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6301600.html
To unsubscribe from Manipulate extract output, click here.

Reply | Threaded
Open this post in threaded view
|

Re: Manipulate extract output

jm3389
I have an additional question.

I know have extracted multiple bands and my list layout has changed.

[[50]]
      SMA-clipped_1 SMA-clipped_2 SMA-clipped_3
 [1,]  0.0632362440    0.14176662     0.8255592
 [2,]  0.1722273529    0.10599104     0.7607671
 [3,]  0.1722273529    0.10599104     0.7607671
 [4,]  0.2838407159    0.05971635     0.6902863
 [5,]  0.0257746875    0.15945776     0.8517801
 [6,]  0.2064613551    0.06632594     0.7841757
 [7,]  0.2064613551    0.06632594     0.7841757
 [8,]  0.2621570826    0.02389294     0.7842789
 [9,]  0.2310775816    0.04211631     0.7626599
[10,]  0.0287268255    0.18798502     0.8102853
[11,]  0.0848897994    0.09991057     0.8653935
[12,]  0.0848897994    0.09991057     0.8653935
[13,]  0.1673026830    0.01770168     0.8713655
[14,]  0.1527486742    0.03026910     0.8653567
[15,]  0.0003926796    0.14994104     0.8714772
[16,]  0.0003926796    0.14994104     0.8714772
[17,]  0.0026585322    0.10952766     0.9157249

[[51]]
      SMA-clipped_1 SMA-clipped_2 SMA-clipped_3
 [1,]    0.15911901     0.3241347     0.5089146
 [2,]    0.15911150     0.3826110     0.4281845
 [3,]    0.15911150     0.3826110     0.4281845
 [4,]    0.10494564     0.2808739     0.5892844
 [5,]    0.14055550     0.2827841     0.5563493
 [6,]    0.13600963     0.3378267     0.4836067
 


How can I get the same output but with this time 3 bands?

      SMA-clipped_1 | SMA-clipped_2 | SMA-clipped_3 | Plot_ID
[1,]  0.0632362440    0.14176662     0.8255592             [[50]]
 [2,]  0.1722273529    0.10599104     0.7607671            [[50]]
 [3,]  0.1722273529    0.10599104     0.7607671            [[50]]
 [4,]  0.2838407159    0.05971635     0.6902863            [[50]]
 [5,]  0.0257746875    0.15945776     0.8517801            [[50]]
 [6,]  0.2064613551    0.06632594     0.7841757            [[50]]
 [7,]  0.2064613551    0.06632594     0.7841757            [[50]]
 [8,]  0.2621570826    0.02389294     0.7842789            [[50]]
 [9,]  0.2310775816    0.04211631     0.7626599            [[50]]
[10,]  0.0287268255    0.18798502     0.8102853           [[50]]
[11,]  0.0848897994    0.09991057     0.8653935           [[50]]
[12,]  0.0848897994    0.09991057     0.8653935           [[50]]
[13,]  0.1673026830    0.01770168     0.8713655           [[50]]
[14,]  0.1527486742    0.03026910     0.8653567           [[50]]
[15,]  0.0003926796    0.14994104     0.8714772           [[50]]
[16,]  0.0003926796    0.14994104     0.8714772           [[50]]
[17,]  0.0026585322    0.10952766     0.9157249           [[50]]

jm3389 wrote
My bad forgot to add utils::

it's working ! Thanks a lot Gustavo

>utils::stack(X)
             values       ind
1     0.0850569680   1
2     0.1152195707   1
3     0.0702793971   1
4     0.0702793971   1
5     0.1055974513   1
6     0.1036369652   1
7     0.0935368910   1
8     0.0935368910   1
9     0.0967371687   1
10    0.1253680587   1
11    0.1569617689   1
12    0.0930611789   1


>
>  On Sun, Apr 24, 2011 at 11:15 AM, Gustavo Carvalho [via R-sig-geo] <
>  [hidden email]<http://user/SendEmail.jtp?type=node&node=6301600&i=1&by-user=t>>
> wrote:
> >
> >> Dear Joseph,
> >>
> >> Could you please try this?
> >>
> >> names(X) <- 1:length(X)
> >> stack(X)
Reply | Threaded
Open this post in threaded view
|

Re: Manipulate extract output

Gustavo Carvalho
Something like this should work:

bleh <- structure(list(`1` = structure(list(a = 1:10, b = 21:30),
.Names = c("a",
"b"), row.names = c(NA, -10L), class = "data.frame"), `2` = structure(list(
    a = 31:40, b = 41:50), .Names = c("a", "b"), row.names = c(NA,
-10L), class = "data.frame"), `3` = structure(list(a = 51:60,
    b = 61:70), .Names = c("a", "b"), row.names = c(NA, -10L), class =
"data.frame")), .Names = c("1",
"2", "3"))

bleh

cbind(Reduce(rbind, bleh), plot = rep(names(bleh), times = sapply(bleh, NROW)))

Don't forget to set the names attribute of your list.

Gustavo.

On Mon, Apr 25, 2011 at 3:45 PM, jm3389 <[hidden email]> wrote:

> I have an additional question.
>
> I know have extracted multiple bands and my list layout has changed.
>
> [[50]]
>      SMA-clipped_1 SMA-clipped_2 SMA-clipped_3
>  [1,]  0.0632362440    0.14176662     0.8255592
>  [2,]  0.1722273529    0.10599104     0.7607671
>  [3,]  0.1722273529    0.10599104     0.7607671
>  [4,]  0.2838407159    0.05971635     0.6902863
>  [5,]  0.0257746875    0.15945776     0.8517801
>  [6,]  0.2064613551    0.06632594     0.7841757
>  [7,]  0.2064613551    0.06632594     0.7841757
>  [8,]  0.2621570826    0.02389294     0.7842789
>  [9,]  0.2310775816    0.04211631     0.7626599
> [10,]  0.0287268255    0.18798502     0.8102853
> [11,]  0.0848897994    0.09991057     0.8653935
> [12,]  0.0848897994    0.09991057     0.8653935
> [13,]  0.1673026830    0.01770168     0.8713655
> [14,]  0.1527486742    0.03026910     0.8653567
> [15,]  0.0003926796    0.14994104     0.8714772
> [16,]  0.0003926796    0.14994104     0.8714772
> [17,]  0.0026585322    0.10952766     0.9157249
>
> [[51]]
>      SMA-clipped_1 SMA-clipped_2 SMA-clipped_3
>  [1,]    0.15911901     0.3241347     0.5089146
>  [2,]    0.15911150     0.3826110     0.4281845
>  [3,]    0.15911150     0.3826110     0.4281845
>  [4,]    0.10494564     0.2808739     0.5892844
>  [5,]    0.14055550     0.2827841     0.5563493
>  [6,]    0.13600963     0.3378267     0.4836067
>
>
>
> How can I get the same output but with this time 3 bands?
>
>      SMA-clipped_1 | SMA-clipped_2 | SMA-clipped_3 | Plot_ID
> [1,]  0.0632362440    0.14176662     0.8255592             [[50]]
>  [2,]  0.1722273529    0.10599104     0.7607671            [[50]]
>  [3,]  0.1722273529    0.10599104     0.7607671            [[50]]
>  [4,]  0.2838407159    0.05971635     0.6902863            [[50]]
>  [5,]  0.0257746875    0.15945776     0.8517801            [[50]]
>  [6,]  0.2064613551    0.06632594     0.7841757            [[50]]
>  [7,]  0.2064613551    0.06632594     0.7841757            [[50]]
>  [8,]  0.2621570826    0.02389294     0.7842789            [[50]]
>  [9,]  0.2310775816    0.04211631     0.7626599            [[50]]
> [10,]  0.0287268255    0.18798502     0.8102853           [[50]]
> [11,]  0.0848897994    0.09991057     0.8653935           [[50]]
> [12,]  0.0848897994    0.09991057     0.8653935           [[50]]
> [13,]  0.1673026830    0.01770168     0.8713655           [[50]]
> [14,]  0.1527486742    0.03026910     0.8653567           [[50]]
> [15,]  0.0003926796    0.14994104     0.8714772           [[50]]
> [16,]  0.0003926796    0.14994104     0.8714772           [[50]]
> [17,]  0.0026585322    0.10952766     0.9157249           [[50]]
>
>
> jm3389 wrote:
>>
>> My bad forgot to add utils::
>>
>> it's working ! Thanks a lot Gustavo
>>
>>>utils::stack(X)
>>              values       ind
>> 1     0.0850569680   1
>> 2     0.1152195707   1
>> 3     0.0702793971   1
>> 4     0.0702793971   1
>> 5     0.1055974513   1
>> 6     0.1036369652   1
>> 7     0.0935368910   1
>> 8     0.0935368910   1
>> 9     0.0967371687   1
>> 10    0.1253680587   1
>> 11    0.1569617689   1
>> 12    0.0930611789   1
>>
>>
>>>
>>>  On Sun, Apr 24, 2011 at 11:15 AM, Gustavo Carvalho [via R-sig-geo] <
>>>  [hidden
>>> email]&lt;http://user/SendEmail.jtp?type=node&amp;node=6301600&amp;i=1&amp;by-user=t&gt;>
>>> wrote:
>>> >
>>> >> Dear Joseph,
>>> >>
>>> >> Could you please try this?
>>> >>
>>> >> names(X) <- 1:length(X)
>>> >> stack(X)
>>
>>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6303557.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Manipulate extract output

jm3389
I works, I dont know why there is quote marks. But I can merge with other data frames, so it's all good for me.

Thank you again for all your help Gustavo

> names(X) <- 1:length(X)
> X.stack <- cbind(Reduce(rbind, X), plot = rep(names(X), times = sapply(X, NROW)))
> X.stack
        SMA-clipped_1           SMA-clipped_2           SMA-clipped_3         plot 
   [1,] "0.0850569680333138"    "0.525055825710297"     "0.391901522874832"   "1"  
   [2,] "0.115219570696354"     "0.433272808790207"     "0.48068830370903"    "1"  
   [3,] "0.0702793970704079"    "0.451244980096817"     "0.480365782976151"   "1"  
   [4,] "0.0702793970704079"    "0.451244980096817"     "0.480365782976151"   "1"  
   [5,] "0.105597451329231"     "0.470949500799179"     "0.450028508901596"   "1"  
   [6,] "0.103636965155602"     "0.436819821596146"     "0.457322180271149"   "1"  
   [7,] "0.0935368910431862"    "0.454399734735489"     "0.45674803853035"    "1"  
   [8,] "0.0935368910431862"    "0.454399734735489"     "0.45674803853035"    "1"  


---------------------------------------------------------
Joseph Muhlhausen
Project development researcher | CIESIN
61 Route 9W, PO Box 1000
Palisades, NY 10964 USA | 845-365-8935




On Mon, Apr 25, 2011 at 5:30 PM, Gustavo Carvalho [via R-sig-geo] <[hidden email]> wrote:
Something like this should work:

bleh <- structure(list(`1` = structure(list(a = 1:10, b = 21:30),
.Names = c("a",
"b"), row.names = c(NA, -10L), class = "data.frame"), `2` = structure(list(
    a = 31:40, b = 41:50), .Names = c("a", "b"), row.names = c(NA,
-10L), class = "data.frame"), `3` = structure(list(a = 51:60,
    b = 61:70), .Names = c("a", "b"), row.names = c(NA, -10L), class =
"data.frame")), .Names = c("1",
"2", "3"))

bleh

cbind(Reduce(rbind, bleh), plot = rep(names(bleh), times = sapply(bleh, NROW)))

Don't forget to set the names attribute of your list.

Gustavo.

On Mon, Apr 25, 2011 at 3:45 PM, jm3389 <[hidden email]> wrote:

> I have an additional question.
>
> I know have extracted multiple bands and my list layout has changed.
>
> [[50]]
>      SMA-clipped_1 SMA-clipped_2 SMA-clipped_3
>  [1,]  0.0632362440    0.14176662     0.8255592
>  [2,]  0.1722273529    0.10599104     0.7607671
>  [3,]  0.1722273529    0.10599104     0.7607671
>  [4,]  <a href="tel:0.2838407159" value="+12838407159" target="_blank">0.2838407159    0.05971635     0.6902863
>  [5,]  0.0257746875    0.15945776     0.8517801
>  [6,]  <a href="tel:0.2064613551" value="+12064613551" target="_blank">0.2064613551    0.06632594     0.7841757
>  [7,]  <a href="tel:0.2064613551" value="+12064613551" target="_blank">0.2064613551    0.06632594     0.7841757
>  [8,]  0.2621570826    0.02389294     0.7842789
>  [9,]  0.2310775816    0.04211631     0.7626599
> [10,]  0.0287268255    0.18798502     0.8102853
> [11,]  0.0848897994    0.09991057     0.8653935
> [12,]  0.0848897994    0.09991057     0.8653935
> [13,]  0.1673026830    0.01770168     0.8713655
> [14,]  0.1527486742    0.03026910     0.8653567
> [15,]  0.0003926796    0.14994104     0.8714772
> [16,]  0.0003926796    0.14994104     0.8714772
> [17,]  0.0026585322    0.10952766     0.9157249
>
> [[51]]
>      SMA-clipped_1 SMA-clipped_2 SMA-clipped_3
>  [1,]    0.15911901     0.3241347     0.5089146
>  [2,]    0.15911150     0.3826110     0.4281845
>  [3,]    0.15911150     0.3826110     0.4281845
>  [4,]    0.10494564     0.2808739     0.5892844
>  [5,]    0.14055550     0.2827841     0.5563493
>  [6,]    0.13600963     0.3378267     0.4836067
>
>
>
> How can I get the same output but with this time 3 bands?
>
>      SMA-clipped_1 | SMA-clipped_2 | SMA-clipped_3 | Plot_ID
> [1,]  0.0632362440    0.14176662     0.8255592             [[50]]
>  [2,]  0.1722273529    0.10599104     0.7607671            [[50]]
>  [3,]  0.1722273529    0.10599104     0.7607671            [[50]]
>  [4,]  <a href="tel:0.2838407159" value="+12838407159" target="_blank">0.2838407159    0.05971635     0.6902863            [[50]]
>  [5,]  0.0257746875    0.15945776     0.8517801            [[50]]
>  [6,]  <a href="tel:0.2064613551" value="+12064613551" target="_blank">0.2064613551    0.06632594     0.7841757            [[50]]
>  [7,]  <a href="tel:0.2064613551" value="+12064613551" target="_blank">0.2064613551    0.06632594     0.7841757            [[50]]
>  [8,]  0.2621570826    0.02389294     0.7842789            [[50]]
>  [9,]  0.2310775816    0.04211631     0.7626599            [[50]]
> [10,]  0.0287268255    0.18798502     0.8102853           [[50]]
> [11,]  0.0848897994    0.09991057     0.8653935           [[50]]
> [12,]  0.0848897994    0.09991057     0.8653935           [[50]]
> [13,]  0.1673026830    0.01770168     0.8713655           [[50]]
> [14,]  0.1527486742    0.03026910     0.8653567           [[50]]
> [15,]  0.0003926796    0.14994104     0.8714772           [[50]]
> [16,]  0.0003926796    0.14994104     0.8714772           [[50]]
> [17,]  0.0026585322    0.10952766     0.9157249           [[50]]
>
>
> jm3389 wrote:
>>
>> My bad forgot to add utils::
>>
>> it's working ! Thanks a lot Gustavo
>>
>>>utils::stack(X)
>>              values       ind
>> 1     0.0850569680   1
>> 2     0.1152195707   1
>> 3     0.0702793971   1
>> 4     0.0702793971   1
>> 5     0.1055974513   1
>> 6     0.1036369652   1
>> 7     0.0935368910   1
>> 8     0.0935368910   1
>> 9     0.0967371687   1
>> 10    0.1253680587   1
>> 11    0.1569617689   1
>> 12    0.0930611789   1
>>
>>
>>>
>>>  On Sun, Apr 24, 2011 at 11:15 AM, Gustavo Carvalho [via R-sig-geo] <
>>>  [hidden
>>> wrote:

>>> >
>>> >> Dear Joseph,
>>> >>
>>> >> Could you please try this?
>>> >>
>>> >> names(X) <- 1:length(X)
>>> >> stack(X)
>>
>>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6303557.html

> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



If you reply to this email, your message will be added to the discussion below:
http://r-sig-geo.2731867.n2.nabble.com/Manipulate-extract-output-tp6301073p6303936.html
To unsubscribe from Manipulate extract output, click here.