Re: [R] [External] Re: Error in setwd(dir) when initializing R

2023-11-20 Thread Ana de las Heras Molina
Hello,

Thank you all for your responses. When I initialize R, the folder in which
it starts is:

getwd()
[1] "C:/Users/Ana/OneDrive - Universidad Complutense de Madrid
(UCM)/Documentos"

So it seems a problem with OneDrive
-Kevin: I do not really understand your question... You mean if I set my
working directory to my C:// or D:// folder in my computer? It doesn't work
either.

-Ivan: this is the message I got when running traceback(). So can I move
the.Rdata file without affecting the work?

-Luke: thank you for the idea, I will try it.

Error in setwd(dir) : no es posible cambiar el directorio de trabajo>
traceback()4: setwd(dir)
3: .rs.onAvailablePackagesStale(reposString)
2: .rs.availablePackages()
1: .rs.rpc.discover_package_dependencies("3C994FEC", ".R")


Best,

Ana


El mar, 21 nov 2023 a las 0:43,  escribió:

> On Mon, 20 Nov 2023, Ivan Krylov wrote:
>
> > On Mon, 20 Nov 2023 12:18:11 +0100
> > Ana de las Heras Molina  wrote:
> >
> >> Error in setwd(dir) : no es posible cambiar el directorio de trabajo
> >
> > If you run traceback() first thing after getting this error, does it
> > say anything useful? (Anything besides "No traceback available" would
> > count as useful.)
> >
> > Do you have a file named .RData in your home directory? If yes, it may
> > help to move it away (or remove it if you don't use the saved session).
>
> Also check for .Rprofile or other profile that might contain a setwd()
> call.  Starting R with --vanilla should work if the issue is a startup
> file.
>
> Best,
>
> luke
>
> >
> >
>
> --
> Luke Tierney
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa  Phone: 319-335-3386
> Department of Statistics andFax:   319-335-3017
> Actuarial Science
> 241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
> Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
>


-- 
*Ana de las Heras Molina*


Nutrición Animal
Departamento de  Producción Animal
Facultad de Veterinaria
Universidad Complutense de Madrid

*Contacto*: 913943855/anaher...@ucm.es

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R-es] Cambiar el intervalo de confianza en un anova

2023-11-20 Thread Relloso Barrio, Juan Bautista
Buenos días.
Normalmente por defecto, todos los ANOVAS (análisis de varianza) que he 
realizado han sido con un intervalo de confianza del 95%.
¿Cuál sería la orden que debería introducir si deseo modificar ese 95% y, por 
ejemplo, bajarlo a un 90%?
Muchas gracias.
 Un saludo.
Juan Bautista Relloso Barrio
Coordinador de Equipos e Infraestructuras | Técnico de Cultivos del 
Departamento de Producción Vegetal
Talde eta Azpiegitura Koordinatzailea | Laborantza teknikaria Landare Ekoizpen 
Departamentua
jbauti...@neiker.eus  | M. 688 62 98 14
www.neiker.eus
[cid:image001.png@01DA1C57.393B21C0]  
 [cid:image002.png@01DA1C57.393B21C0]  
[cid:image003.png@01DA1C57.393B21C0]   
[cid:image004.png@01DA1C57.393B21C0] 
[cid:image005.png@01DA1C57.393B21C0][ej_ekonomia_garapen_lateral]   

[https://www.emakunde.euskadi.eus/contenidos/informacion/violencia_puntolila/eu_def/adjuntos/punto.lila.jpg]

PRIBATUTASUN POLITIKA | POLÍTICA 
DE PRIVACIDAD | LEGAL 
NOTICE



De: R-help-es  En nombre de Relloso Barrio, 
Juan Bautista
Enviado el: miércoles, 11 de octubre de 2023 10:32
Para: r-help-es@r-project.org
Asunto: Re: [R-es] Hacer un Split plot

Buenos días.
Perdón por insistir. Quiero hacer un ANOVA para unos datos que tienen un diseño 
Split plot.
Y estoy utilizando dos editores diferentes, que, si todo fuera correcto y ya 
que toman los mismos datos, me debería dar el mismo resultado, … pero no es así.
Querría saber si básicamente los dos hacen un análisis de varianza SPLIT PLOT 
?. Y el mismo análisis?
Los comandos que doy son estos:
CEPAS, es el nombre del archivo de datos.
model<-with(CEPAS, sp.plot(REP, CEPA, VARIEDAD, trAUDPC))
Y el otro es este
model2.aov<- aov(trAUDPC~CEPA*VARIEDAD+REP+Error(REP/CEPA))

 Un saludo.
Juan Bautista Relloso Barrio
Coordinador de Equipos e Infraestructuras | Técnico de Cultivos del 
Departamento de Producción Vegetal
Talde eta Azpiegitura Koordinatzailea | Laborantza teknikaria Landare Ekoizpen 
Departamentua
jbauti...@neiker.eus  | M. 688 62 98 14
www.neiker.eus
[cid:image001.png@01DA1C57.393B21C0]  
 [cid:image002.png@01DA1C57.393B21C0]  
[cid:image003.png@01DA1C57.393B21C0]   
[cid:image004.png@01DA1C57.393B21C0] 
[cid:image005.png@01DA1C57.393B21C0][ej_ekonomia_garapen_lateral]   

[https://www.emakunde.euskadi.eus/contenidos/informacion/violencia_puntolila/eu_def/adjuntos/punto.lila.jpg]

PRIBATUTASUN POLITIKA | POLÍTICA 
DE PRIVACIDAD | LEGAL 
NOTICE



De: R-help-es 
mailto:r-help-es-boun...@r-project.org>> En 
nombre de Relloso Barrio, Juan Bautista
Enviado el: viernes, 22 de septiembre de 2023 16:18
Para: r-help-es@r-project.org
Asunto: [R-es] no encuentro el error

Buenas tardes.
Intento hacer la separación de medias “por tratamientos”
Pero me da un error que no consigo corregir. No sé que hago mal. Os paso los 
comandos y el error

# Separación de medias HSD por Tratamiento No funciona
by(, $TRAT, function(x) {
  anova_result <- aov(RTOSE ~ CORTE, data = x)
  HSD_result <- HSD.test(anova_result)
  Tratamiento <- unique(x$TRAT)
  return(list(Tratamiento = TRAT, HSD_result = HSD_result))
})
Y el error es este:
Error in pmatch(trt, names(A)) :
argument "trt" is missing, with no default

 Un saludo.
Juan Bautista Relloso Barrio
Coordinador de Equipos e Infraestructuras | Técnico de Cultivos del 
Departamento de Producción Vegetal
Talde eta Azpiegitura Koordinatzailea | Laborantza teknikaria Landare Ekoizpen 
Departamentua
jbauti...@neiker.eus  | M. 688 62 98 14
www.neiker.eus
[cid:image001.png@01DA1C57.393B21C0]  
 [cid:image002.png@01DA1C57.393B21C0]  
[cid:image003.png@01DA1C57.393B21C0]   
[cid:image004.png@01DA1C57.393B21C0] 
[cid:image005.png@01DA1C57.393B21C0][ej_ekonomia_garapen_lateral]   

[https://www.emakunde.euskadi.eus/contenidos/informacion/violencia_puntolila/eu_def/adjuntos/punto.lila.jpg]

PRIBATUTASUN POLITIKA | POLÍTICA 
DE PRIVACIDAD | LEGAL 

Re: [R] Calculating volume under polygons

2023-11-20 Thread Micha Silver

(Keeping on the list. And consider my suggestion to move this to R-sig-Geo)


What is the coordinate reference system of the polygon layer? Can you 
share these layers?



On 21/11/2023 4:58, javad bayat wrote:

Dear Micha;
Thank you for your reply.
The R version is 4.3.2, the raster package is "raster_3.6-26", the sf 
package is "sf_1.0-14".

The str of the raster and polygon is as follow:
> str(r)
Formal class 'RasterLayer' [package "raster"] with 13 slots
  ..@ file    :Formal class '.RasterFile' [package "raster"] with 13 slots
  .. .. ..@ name        : chr "E:\Base1.tif"
  .. .. ..@ datanotation: chr "INT2S"
  .. .. ..@ byteorder   : chr "little"
  .. .. ..@ nodatavalue : num -Inf
  .. .. ..@ NAchanged   : logi FALSE
  .. .. ..@ nbands      : int 1
  .. .. ..@ bandorder   : chr "BIL"
  .. .. ..@ offset      : int 0
  .. .. ..@ toptobottom : logi TRUE
  .. .. ..@ blockrows   : Named int 128
  .. .. .. ..- attr(*, "names")= chr "rows"
  .. .. ..@ blockcols   : Named int 128
  .. .. .. ..- attr(*, "names")= chr "cols"
  .. .. ..@ driver      : chr "gdal"
  .. .. ..@ open        : logi FALSE
  ..@ data    :Formal class '.SingleLayerData' [package "raster"] with 
13 slots

  .. .. ..@ values    : logi(0)
  .. .. ..@ offset    : num 0
  .. .. ..@ gain      : num 1
  .. .. ..@ inmemory  : logi FALSE
  .. .. ..@ fromdisk  : logi TRUE
  .. .. ..@ isfactor  : logi FALSE
  .. .. ..@ attributes: list()
  .. .. ..@ haveminmax: logi TRUE
  .. .. ..@ min       : num 1801
  .. .. ..@ max       : num 3289
  .. .. ..@ band      : int 1
  .. .. ..@ unit      : chr ""
  .. .. ..@ names     : chr "Base1"
  ..@ legend  :Formal class '.RasterLegend' [package "raster"] with 5 
slots

  .. .. ..@ type      : chr(0)
  .. .. ..@ values    : logi(0)
  .. .. ..@ color     : logi(0)
  .. .. ..@ names     : logi(0)
  .. .. ..@ colortable: logi(0)
  ..@ title   : chr(0)
  ..@ extent  :Formal class 'Extent' [package "raster"] with 4 slots
  .. .. ..@ xmin: num 330533
  .. .. ..@ xmax: num 402745
  .. .. ..@ ymin: num 3307321
  .. .. ..@ ymax: num 3345646
  ..@ rotated : logi FALSE
  ..@ rotation:Formal class '.Rotation' [package "raster"] with 2 slots
  .. .. ..@ geotrans: num(0)
  .. .. ..@ transfun:function ()
  ..@ ncols   : int 5777
  ..@ nrows   : int 3066
  ..@ crs     :Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr NA
  ..@ srs     : chr "+proj=utm +zone=40 +datum=WGS84 +units=m +no_defs"
  ..@ history : list()
  ..@ z       : list()

> str(p)
sf [12 × 10] (S3: sf/tbl_df/tbl/data.frame)
 $ Name      : chr [1:12] "01" "02" "03" "04" ...
 $ FolderPath: chr [1:12]  ...
 $ SymbolID  : num [1:12] 0 0 0 0 0 0 0 0 0 0 ...
 $ AltMode   : int [1:12] 0 0 0 0 0 0 0 0 0 0 ...
 $ Base      : num [1:12] 0 0 0 0 0 0 0 0 0 0 ...
 $ Clamped   : int [1:12] -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
 $ Extruded  : int [1:12] 0 0 0 0 0 0 0 0 0 0 ...
 $ Shape_Area: num [1:12] 63.51 15.28 9.23 39.19 642.38 ...
 $ Area      : num [1:12] 64 15 9 39 642 56 36 16 53 39 ...
 $ geometry  :sfc_POLYGON of length 12; first list element: List of 1
  ..$ : num [1:18, 1:3] 55.6 55.6 55.6 55.6 55.6 ...
  ..- attr(*, "class")= chr [1:3] "XYZ" "POLYGON" "sfg"
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA 
NA NA NA NA NA NA NA
  ..- attr(*, "names")= chr [1:9] "Name" "FolderPath" "SymbolID" 
"AltMode" ...

Sincerely







On Mon, Nov 20, 2023 at 5:15 PM Micha Silver  wrote:

Hi:

Some preliminary comments first

1- You might get a better response posting to R-sig-Geo

2- Probably better to switch to the `terra` package instead of the
older
`raster`

3- Furthermore, there is the package `exactextractr` that ensures
that
edge pixels are taken into account, weighted by the actual, partial
coverage of each pixel by the polygon.

4- Can you post: your R version, and version of the relevant
packages,
and information about the polygons and DEM (i.e. `str(p)` and
`str(r)` )


On 20/11/2023 14:30, javad bayat wrote:
> Dear all;
> I am trying to calculate volume under each polygon of a
shapefile according
> to a DEM.
> when I run the code, it gives me an error as follows.
> "
> Error in h(simpleError(msg, call)) :
>    error in evaluating the argument 'x' in selecting a method
for function
> 'addAttrToGeom': sp supports Z dimension only for POINT and
MULTIPOINT.
> use `st_zm(...)` to coerce to XY dimensions
> "
> I want to have a table that contains one column corresponding to the
> polygon rank and another that contains the volume on that polyon.
> I would be more than happy if anyone could help me.
> I provided codes at the end of this email.
> Sincerely
>
>
>

##
> library(raster);
> library(sf)
> # Load the DEM raster and shapefile
> r <- 

Re: [R] [External] Re: Error in setwd(dir) when initializing R

2023-11-20 Thread luke-tierney

On Mon, 20 Nov 2023, Ivan Krylov wrote:


On Mon, 20 Nov 2023 12:18:11 +0100
Ana de las Heras Molina  wrote:


Error in setwd(dir) : no es posible cambiar el directorio de trabajo


If you run traceback() first thing after getting this error, does it
say anything useful? (Anything besides "No traceback available" would
count as useful.)

Do you have a file named .RData in your home directory? If yes, it may
help to move it away (or remove it if you don't use the saved session).


Also check for .Rprofile or other profile that might contain a setwd()
call.  Starting R with --vanilla should work if the issue is a startup
file.

Best,

luke






--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Cannot calculate confidence intervals NULL

2023-11-20 Thread varin sacha via R-help
Dear Bert,
Dear All,

Yes, thanks ! that was the problem!







Le mercredi 15 novembre 2023 à 22:21:53 UTC+1, Bert Gunter 
 a écrit : 





I believe the problem is here:

cor1 <- cor(x1, y1, method="spearman")
 cor2 <- cor(x2, y2, method="spearman")

The x's and y's are not looked for in data (i.e. NSE) but in the environment 
where the function was defined, which is standard evaluation. Change the above 
to:

cor1 <- with(d, cor(x1, y1, method="spearman"))
 cor2 <- with(d, cor(x2, y2, method="spearman"))

and all should be fine.

-- Bert

On Wed, Nov 15, 2023 at 12:54 PM varin sacha via R-help  
wrote:
> R-Experts,
> 
> Here below my R code working without error message but I don't get the 
> results I am expecting.
> Here is the result I get:
> 
> [1] "All values of t are equal to 0.28611928397257 \n Cannot calculate 
> confidence intervals"
> NULL
> 
> If someone knows how to solve my problem, really appreciate.
> Best,
> S
> 
> 
> #
> # Difference in Spearman rho 
> 
> library(boot)
>  
> x1=c(4,6,5,7,8,4,2,3,5.5,6.7,5.5,3.5,2,1,3,5,6,3.5,2.5,2,1,2,3,2,1,2,3,4,3,4)
>  
> y1=c(10,14,12.5,21,15,16,17.5,11,11.5,21,19,16,17.5,18,18.5,12,13,14,11,11,12,18,20,13,23,12,11,14,16,11)
>  
> x2=c(5,3,4,2,1,1,1,2,3,4,5,4,3,2,1,3,4.5,4.5,5.5,6,5,4,7,8,3,4,2,5,4,3)
>  
> y2=c(11,12,13,11,10,19,21,21,13,15,18,13,12,14,19,18.5,17.5,12.5,10,9,11,13,14,16,11,18,14,13,12,12)
>  
> # Function to calculate the difference in Spearman coefficients
> pearson_diff <- function(data, indices) {
>  
> # Sample the data
>   d <- data[indices, ]
>  
>  # Calculate the Spearman correlation coefficients for every sample
>   cor1 <- cor(x1, y1, method="spearman")
>   cor2 <- cor(x2, y2, method="spearman")
>  
> # Return the difference
>   return(cor1 - cor2)
> }
>  
> # Create a data.frame with the data
> data <- data.frame(x1, y1, x2, y2)
>  
> # Use the boot function to apply the bootstrap
> set.seed(123) # For reproducibility
> bootstrap_results <- boot(data = data, statistic = pearson_diff, R = 1000)
>  
> # Calculate all the 95% confidence interval
> boot.ci(bootstrap_results, type = "all")
> ###
>  
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
> 

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Error in setwd(dir) when initializing R

2023-11-20 Thread Ivan Krylov
On Mon, 20 Nov 2023 12:18:11 +0100
Ana de las Heras Molina  wrote:

> Error in setwd(dir) : no es posible cambiar el directorio de trabajo

If you run traceback() first thing after getting this error, does it
say anything useful? (Anything besides "No traceback available" would
count as useful.)

Do you have a file named .RData in your home directory? If yes, it may
help to move it away (or remove it if you don't use the saved session).

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Error in setwd(dir) when initializing R

2023-11-20 Thread Kevin Thorpe
I think that you may be correct about OneDrive being related.

I have seen OneDrive associated with problems before.

What happens if you manually set the working directory to that location? Does 
it work if your default home directory is local to your machine?


> On Nov 20, 2023, at 6:18 AM, Ana de las Heras Molina  wrote:
> 
> [You don't often get email from andel...@ucm.es. Learn why this is important 
> at https://aka.ms/LearnAboutSenderIdentification ]
> 
> Hello,
> I am Ana de las Heras, and I write to you because every time I open RStudio
> or R directly I have the following message, before I can do anything at
> all:
> 
> Error in setwd(dir) : no es posible cambiar el directorio de trabajo
> 
> 
> At first I didn't pay much attention to it, but I am having lots of
> troubles with different programs, including LinDa, ANCOMBC or Genome
> InfoDbdata (and thus, phyloseq). After asking in the different forus of
> each program, they have told me that the issue is more related to my R
> installation and that first message I obtain when I start the program.
> 
> I would be very grateful if someone could help me. This issue started when
> I installed the latest version of R (4.3.1. and now 4.3.2.). I have already
> uninstalled and reinstalled both programs, as well as Rtools. I am not sure
> if the issue could be related to ONe Drive, since the HOME folder is in
> OneDrive. I am currently working on Windows 10, 64 bits.
> 
> Yours faithfully,
> Ana
> --
> *Ana de las Heras Molina*
> 
> 
> Nutrición Animal
> Departamento de  Producción Animal
> Facultad de Veterinaria
> Universidad Complutense de Madrid
> 
> *Contacto*: 913943855/anaher...@ucm.es
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Error in setwd(dir) when initializing R

2023-11-20 Thread Ana de las Heras Molina
Hello,
I am Ana de las Heras, and I write to you because every time I open RStudio
or R directly I have the following message, before I can do anything at
all:

Error in setwd(dir) : no es posible cambiar el directorio de trabajo


At first I didn't pay much attention to it, but I am having lots of
troubles with different programs, including LinDa, ANCOMBC or Genome
InfoDbdata (and thus, phyloseq). After asking in the different forus of
each program, they have told me that the issue is more related to my R
installation and that first message I obtain when I start the program.

I would be very grateful if someone could help me. This issue started when
I installed the latest version of R (4.3.1. and now 4.3.2.). I have already
uninstalled and reinstalled both programs, as well as Rtools. I am not sure
if the issue could be related to ONe Drive, since the HOME folder is in
OneDrive. I am currently working on Windows 10, 64 bits.

Yours faithfully,
Ana
-- 
*Ana de las Heras Molina*


Nutrición Animal
Departamento de  Producción Animal
Facultad de Veterinaria
Universidad Complutense de Madrid

*Contacto*: 913943855/anaher...@ucm.es

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Calculating volume under polygons

2023-11-20 Thread Micha Silver

Hi:

Some preliminary comments first

1- You might get a better response posting to R-sig-Geo

2- Probably better to switch to the `terra` package instead of the older 
`raster`


3- Furthermore, there is the package `exactextractr` that ensures that 
edge pixels are taken into account, weighted by the actual, partial 
coverage of each pixel by the polygon.


4- Can you post: your R version, and version of the relevant packages, 
and information about the polygons and DEM (i.e. `str(p)` and `str(r)` )



On 20/11/2023 14:30, javad bayat wrote:

Dear all;
I am trying to calculate volume under each polygon of a shapefile according
to a DEM.
when I run the code, it gives me an error as follows.
"
Error in h(simpleError(msg, call)) :
   error in evaluating the argument 'x' in selecting a method for function
'addAttrToGeom': sp supports Z dimension only for POINT and MULTIPOINT.
use `st_zm(...)` to coerce to XY dimensions
"
I want to have a table that contains one column corresponding to the
polygon rank and another that contains the volume on that polyon.
I would be more than happy if anyone could help me.
I provided codes at the end of this email.
Sincerely


##
library(raster);
library(sf)
# Load the DEM raster and shapefile
r <- raster("E:/Base1.tif")
p <- read_sf(dsn = "E:/Sites.shp", layer = " Sites")



Now to the question:

In `read_sf()`, when the source is a shapefile, you do not need the 
'layer' option. It doesn't hurt, but in this case I see that you have an 
extra space before the layer name. Could that be causing the problem?





# Extract the values of the DEM raster for each polygon
values <- extract(r, p)
   Error in h(simpleError(msg, call)) :
   error in evaluating the argument 'x' in selecting a method for function
'addAttrToGeom': sp supports Z dimension only for POINT and MULTIPOINT.
use `st_zm(...)` to coerce to XY dimensions

# Calculate the volume of each polygon
volumes <- sapply(values, function(x) rasterVolume(x, r))


What is this "rasterVolume" function that you call here?



# Print the results
for (i in 1:length(volumes)) {
   cat(sprintf("Volume under polygon %d: %f\n", i, volumes[i]))
}
##






--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Calculating volume under polygons

2023-11-20 Thread javad bayat
Dear all;
I am trying to calculate volume under each polygon of a shapefile according
to a DEM.
when I run the code, it gives me an error as follows.
"
Error in h(simpleError(msg, call)) :
  error in evaluating the argument 'x' in selecting a method for function
'addAttrToGeom': sp supports Z dimension only for POINT and MULTIPOINT.
use `st_zm(...)` to coerce to XY dimensions
"
I want to have a table that contains one column corresponding to the
polygon rank and another that contains the volume on that polyon.
I would be more than happy if anyone could help me.
I provided codes at the end of this email.
Sincerely


##
library(raster);
library(sf)
# Load the DEM raster and shapefile
r <- raster("E:/Base1.tif")
p <- read_sf(dsn = "E:/Sites.shp", layer = " Sites")
# Extract the values of the DEM raster for each polygon
values <- extract(r, p)
  Error in h(simpleError(msg, call)) :
  error in evaluating the argument 'x' in selecting a method for function
'addAttrToGeom': sp supports Z dimension only for POINT and MULTIPOINT.
use `st_zm(...)` to coerce to XY dimensions

# Calculate the volume of each polygon
volumes <- sapply(values, function(x) rasterVolume(x, r))
# Print the results
for (i in 1:length(volumes)) {
  cat(sprintf("Volume under polygon %d: %f\n", i, volumes[i]))
}
##





-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] anyone having trouble accesing CRAN?

2023-11-20 Thread peter dalgaard
Notice that getCRANmirrors() without the local.only=TRUE gets its list from 
...tada cran.r-project.org. 

Arguably, that might be in for a change. Meanwhile, you might just use 
cloud.r-project.org right away.  

-pd

> On 15 Nov 2023, at 20:23 , Ivan Krylov  wrote:
> 
> On Wed, 15 Nov 2023 14:13:00 -0500
> "Christopher W. Ryan via R-help"  wrote:
> 
>> Anyone seeing similar?
> 
> Same for me.
> 
> While it worked, CRAN website had the following message:
> 
>>> The CRAN Admin Team will perform system upgrades during the period
>>> Wednesday November 15 until Thursday November 16, 2023. There will
>>> be intermittent outages in service during this time. 
> 
> Use chooseCRANmirror(local.only = TRUE) (or subset() the return value
> of getCRANmirrors(local.only = TRUE)) to access a mirror that works.
> 
> -- 
> Best regards,
> Ivan
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.