[R] Calculating angle of a polyline

2018-01-30 Thread javad bayat
Dear R users
I am trying to find a formula to calculate the angle of a polyline. Is
there a way to do this?
Many thanks.

-- 
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.


[R] Deleting a specific value in a column of a data frame

2018-06-23 Thread javad bayat
Dear R users;
I have two columns data frame (column names is A and B). I want to write a
function in order to compare column of B with A and if the values of B are
equal or greater than that of A, replace them with "NA" or delete them and
if the values of B are less than values in A, do nothing.

Sincerely.

-- 
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.


[R] How to get bathymetry data using R

2016-06-10 Thread javad bayat
Dear R users;
I am searching for a package to extract bathymetry data from topography map
to produce the control file for CE-Qual-w2 model.
Is there anyone to know how to do it?
many thanks.

-- 
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] How to get bathymetry data using R

2016-06-11 Thread javad bayat
Dear all;
Many thanks for your answers but I think I should explain more. What I want
to do is extracting bathymetry data from topography or DEM for a model that
uses .npt format.
Is there a package to do such a thing?
Thanks.

On Sat, Jun 11, 2016 at 8:39 PM, Roy Mendelssohn - NOAA Federal <
roy.mendelss...@noaa.gov> wrote:

> Use the “rerddap” package that accesses our ERDDAP server.  You can see
> the data available at:
>
> http://upwell.pfeg.noaa.gov/erddap
>
> In the search box type in “bathymetry”.You can subset as you want,
> using “rerddap” you get back a netcdf file that is already read into your R
> workspace,  or you can write your own 2 lines of code  (since the URL
> completely defines the request) and get the data back in any number of file
> formats.  I don’t want to get into a format war, but for large gridded
> datasets like this I much prefer netcdf files.
>
> If you have any questions at all about either the “rerddap” package
> (developed by the wonderful people at ROpenSci) or about our ERDDAP
> service, don’t hesitate to ask.
>
> -Roy
>
> > On Jun 11, 2016, at 12:30 AM, Michael Sumner  wrote:
> >
> > On Sat, 11 Jun 2016 at 15:43 javad bayat  wrote:
> >
> >> Dear R users;
> >> I am searching for a package to extract bathymetry data from topography
> map
> >> to produce the control file for CE-Qual-w2 model.
> >> Is there anyone to know how to do it?
> >> many thanks.
> >>
> >>
> > There are few things around but I highly recommend find your own data
> > source, suitable for your purpose - and reading it directly with the
> raster
> > package.  If anyone knows a reliable source I'd like to hear it.
> >
> > As a global go-to I use Etopo1, but you may want some more detailed (like
> > Gebco 2014) or a non-global one. (I can't tell where you need this for or
> > what resolution would be suitable from what you've asked though).
> >
> > (The best format when you get a choice generally is GeoTIFF, but it
> depends
> > who creates them. I tend to use the NetCDF files from Etopo).
> >
> > Raster uses rgdal for many formats, but ncdf4 exclusively for NetCDF - if
> > it's not called "*.nc" you can get around that).
> >
> > Cheers, Mike.
> >
> >
> >
> >> --
> >> 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.
> >>
> > --
> > Dr. Michael Sumner
> > Software and Database Engineer
> > Australian Antarctic Division
> > 203 Channel Highway
> > Kingston Tasmania 7050 Australia
> >
> >   [[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.
>
> **
> "The contents of this message do not reflect any position of the U.S.
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new address and phone***
> 110 Shaffer Road
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK
> Jr.
>
>


-- 
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.

[R] CCA package

2015-06-25 Thread javad bayat
Dear R users;
I am using CCA package to calculate the correlation between two data set.
Every time that I run my codes, I get the following error;
"the leading minor of order 5 is not positive definite".
Please help me to fix it.
Many thanks.

-- 
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.


[R] correlation matricies: getting p-values?

2015-06-28 Thread JAVAD BAYAT
Dear Bill Venables;

Hi, I am using "cor" command to get the correlation coefficients for my data
frame. I found somthing in the following site: "

https://stat.ethz.ch/pipermail/r-help/2000-January/009758.html"; . I used
your functions to get the p-values for each variables. But I want to use
Spearman method for my data frame. 

Please help me to write the right function.

many thanks.

 


[[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] Extract the coordinates of a Polylines

2019-01-27 Thread javad bayat
Dear R users;
I am trying to extract the X and Y coordinates of a polylines along with
Elevation data. I have extracted the Elevations as Z, but I do not know how
to extract the X and Y of these Elevations. Is it possible to extract X and
Y of the Elevation and create a data frame with three variables?

line = readOGR("E://Topo.shp")
Z = line@data$Elevation

Sincerely.

-- 
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] Extract the coordinates of a Polylines

2019-01-31 Thread javad bayat
Dear all;
Back to my previous question, I am trying to add X and Y coordinates to
every row of the data.

topo =
readOGR("E:/New/Modelling_Water/MIKE/BathyMetry/GIS_Armator/Chitgar_Topo.shp")#Read
shape file of the topo as polylines
plot(topo)
cords = topo@lines[[1]]@Lines[[1]]@coords###Extracting X and Y coordinates
of the polylines of topo

head(topo@data)
  FID_ Entity   Layer Color   Linetype Elevation
0 LWPolyline C-TOPO-MAJR 9 Continuous1258.0
0 LWPolyline C-TOPO-MAJR 9 Continuous1258.5
0 LWPolyline C-TOPO-MAJR 9 Continuous1258.5
0 LWPolyline C-TOPO-MAJR 9 Continuous1258.5
0 LWPolyline C-TOPO-MAJR 9 Continuous1258.5
0 LWPolyline C-TOPO-MAJR 9 Continuous1258.5

How can I do this.
Sincerely.

On Sat, Jan 26, 2019 at 9:37 AM javad bayat  wrote:

> Dear R users;
> I am trying to extract the X and Y coordinates of a polylines along with
> Elevation data. I have extracted the Elevations as Z, but I do not know how
> to extract the X and Y of these Elevations. Is it possible to extract X and
> Y of the Elevation and create a data frame with three variables?
>
> line = readOGR("E://Topo.shp")
> Z = line@data$Elevation
>
> Sincerely.
>
> --
> Best Regards
> Javad Bayat
> M.Sc. Environment Engineering
> Alternative Mail: bayat...@yahoo.com
>


-- 
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.


[R] Problem with combining 2 data frame

2019-02-15 Thread javad bayat
Dear R users;
I am trying to combine 2 dataframes with different rows, 26 and 6 rows. The
first column of both dataframe has something in common, and I want to
compare the first column of the df1 with first column of the df2 to see if
they are same or not. Then if they were same, the second column of the df1
fill by the value of the second column of df2.

df1 = data.frame(x1 = letters[1:26],x2 = NA)
df2 = data.frame(x1 = letters[10:15],x2 = c("1a","2a","3a","4a","5a","6a"))

f = function(x,y){
  for (i in 1:nrow(df1))
   ifelse(df1$x1 == df2$x1, df1$x2==df2$x2, "NA")}
f(df1,df2)
Error in Ops.factor(df1$x1, df2$x1) : level sets of factors are different

Is there anyone to help me to solve this problem?
Sincerely.










-- 
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.


[R] N.network help

2014-11-19 Thread Javad Bayat
Dear all;I want to do N.network for pH and predict its future.but when I run 
the code and plot them (the measured data and the predicted), the predicted 
data in all station are same.i do not know what is wrong with this. Here are 
the codes that I used:"fit  <- neuralnet(pH ~ station.2 + Day,data = bayat2)## 
create new data into the futurefuturedata <- expand.grid(station.2 = 1:5, Day = 
511:1000)
## do predictionspredictions <- compute(fit, futuredata)predictions2 <- 
data.frame(predictions[["neurons"]][[1]][,2:3], pH = 
predictions$net.result)head(predictions2)## plot the results together with 
original datalibrary(lattice)library(latticeExtra)xyplot(pH ~ 
Day|factor(station.2), data = bayat2, type = "b", layout = c(3,2), xlim = 
c(0:1000))+xyplot(pH ~ Day|factor(station.2), data = predictions2, type = "b", 
layout = c(4,2), col = "red")"

Many thanks.
 Best Regards
Javad Bayat
Alternative Mail: j.bayat...@gmail.com
[[alternative HTML version deleted]]

__
R-help@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.


[R] prediction with neural network

2015-11-13 Thread javad bayat
Hi all;
I am working with a data set, pH of a lake water, and there is some gap in
my data. I it possible to predict these gaps by neural network? If so
please help to use the right code.
Many thanks.






-- 
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.


[R] Prediction data gaps by "neuralnet" package

2015-11-19 Thread javad bayat
Dear R users;
I am trying to predict the gaps in my data set (colorofil.A) by using
"neuralnet" package. But when I run the following codes it gives me error.
Could anyone help me to fix the problem?
Bests.

> library("neuralnet")

> head(ss1,2)[,c(5,24)]
  Season  colorofil.A
1   Sp  NA
2   Sp  10

> net.sqrt <- neuralnet(colorofil.A~Season,ss1, hidden=10, threshold=0.01)
print(net.sqrt)











-- 
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.


[R] Split Dataframe into several

2021-03-08 Thread javad bayat
Dear R users;
Hi.
I have a problem with splitting dataframe into several.
I have a large dataframe (Length of 61000). It has 4 Columns as below:
"
   Date Cases  Country
12020-12-14 746Country1
22020-12-15  324   Country1
..
6000  2020-12-13  298Country2
.
.
"
Each country has a different number of rows and their related dates are
different. What I want to do is: Extract rows for each country and make a
new column for that case of the country.
"
 Date Cases_Country1  Cases_Country2
 Cases_Country3 ..
1   2020-12-14 746  25
65
2   2020-12-15  324
..
6000  2020-12-13  298  352
  75
"
I used split function, but it create a list and I cannot use the data.
Please help me to fix this problem.
Sincerely



-- 
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.


[R] Increasing the resolution of a raster

2021-03-23 Thread javad bayat
Dear R users;
Is there any way to increase the resolution of a raster so as to be seen
more clear?
I have a raster which is not very clear. I want to read it in R and get its
values and increase the resolution to be seen clearly.
please help me to do this.
I have tried using the following codes, but did not work.

bayat <- raster("./Bayat.jpg")
bayat
class  : RasterLayer
band   : 1  (of  3  bands)
dimensions : 1181, 827, 976687  (nrow, ncol, ncell)
resolution : 1, 1  (x, y)
extent : 0, 827, 0, 1181  (xmin, xmax, ymin, ymax)
crs: NA
source : E:/New/Bayat.jpg
names  : Bayat
values : 0, 255  (min, max)

bayat2 <- bayat
bayat_value = data.frame(xyFromCell(bayat2, 1:ncell(bayat2)))
valu <- getValues(bayat2)
i <- !is.na(valu)
bayat_value <- bayat_value[i,]
valu <- valu[i]
library(fields)
gc()
tps <- Tps(bayat_value, valu)
bayat3 <- raster(bayat)
bayat3 <- interpolate(bayat3, tps)
bayat3 <- mask(bayat3, bayat)
plot(bayat3)



Sincerely



-- 
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.


[R] Fwd: Create new polygon from a polygon

2021-04-21 Thread javad bayat
-- Forwarded message -
From: javad bayat 
Date: Fri, Apr 16, 2021 at 9:00 AM
Subject: Create new polygon from a polygon
To: 


Dear all;
I have a polygon and I want to divide it into 2 new polygons. The first one
must be 54 percent of the initial polygon area and the remaining area (46
percent of the area) for the second polygon. Is there any way to do this?

"
library(rgdal)
S_P = readOGR(".","Polygon")
proj4string(S_P) <- CRS("+proj=utm +zone=39 +datum=WGS84")

"
Sincerely

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


-- 
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.


[R] Satelit Image

2021-07-26 Thread javad bayat
Dear all;
I want to extrac special wavelength of landsat8 image, 470nm and 570nm.
Is there any way to do this?
Sincerely

-- 
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.


[R] High error made by Neural network in R

2022-07-30 Thread javad bayat
Dear all;
I have run a neural network to predict a variable according to 3
independent variables. I used "neuralnet" package and the codes were:
"
> met = read.csv("./met.csv",header = TRUE, sep = ",")
> attach(met)
> head(met)
> met2 = met
> str(met2)
'data.frame':   211362 obs. of  4 variables:
 $ t: num  14.9 13.9 16.3 16 13.4 ...
 $ rrr24: num  NA NA NA NA NA NA NA NA NA NA ...
 $ sshn : num  NA NA NA NA NA NA NA NA NA NA ...
 $ u: num  56.9 67.5 87.1 88.6 82 ...
> met2 = na.omit(met2)
> dim(met2)
[1] 130765  4


> set.seed(7896129)
> test_met <- read.csv("./test_met.csv",header = TRUE, sep = ",")
> attach(test_met)
> head(test_met)
> test_met = na.omit(test_met)
> dim(test_met)
[1] 73778 4

> n2 <- neuralnet(u ~ t + rrr24 + sshn,
   data = met2,
   hidden = 4,
   err.fct = "sse",
   linear.output = TRUE,
   lifesign = 'full',
   rep = 1,
   algorithm = "rprop+",
   stepmax = 10,
   threshold = 0.01
   )
hidden: 4thresh: 0.01rep: 1/1steps: 138 error:
30691876.99866   time: 6.35 secs

> n2$result.matrix
  [,1]
error 3.069188e+07
reached.threshold 8.661171e-03
steps 1.38e+02
Intercept.to.1layhid1 1.391861e+01
t.to.1layhid1 2.917817e+00
rrr24.to.1layhid1 1.272637e+01
sshn.to.1layhid1  1.302440e+01
Intercept.to.1layhid2 1.418934e+01
t.to.1layhid2 3.010978e+00
rrr24.to.1layhid2 1.453077e+01
sshn.to.1layhid2  1.373876e+01
Intercept.to.1layhid3 1.458518e+01
t.to.1layhid3 3.028105e+00
rrr24.to.1layhid3 1.315952e+01
sshn.to.1layhid3  1.390079e+01
Intercept.to.1layhid4 1.255582e+01
t.to.1layhid4 2.520585e+00
rrr24.to.1layhid4 1.223544e+01
sshn.to.1layhid4  1.146831e+01
Intercept.to.u8.018417e+00
1layhid1.to.u 8.222817e+00
1layhid2.to.u 8.355812e+00
1layhid3.to.u 9.095662e+00
1layhid4.to.u 8.024959e+00

> results_met <- neuralnet::compute(n2, test_met[,1:3])
"
I am confused why the error is so high ( 3.069188e+07). Is it a problem
regarding my codes?
Is the prediction made by this neural network accurate?
Sincerely



-- 
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.


[R] Getting minimum value of a column according a factor column of a dataframe

2022-08-24 Thread javad bayat
Dear all;
I am trying to get the minimum value of a column based on a factor column
of the same data frame. My data frame is like the below:
   Code   Y   MD
 Q
 N  O
41003 81 1 19 0.16 7.17 2.5
41003 77 9 22 0.197 6.8 2.2
41003 79 7 28 0.21 4.7 6.2
41005 79 8 17 0.21 5.5 7.2
41005 80 10 30 0.21 6.84 2.6
41005 80 12 20 0.21 6.84 2.4
41005 79 6 14 0.217 5.61 3.55
41009 79 2 21 0.218 5.56 4.04
41009 79 5 27 0.218 6.4 3.12
41009 80 11 29 0.22 6.84 2.8
41009 78 5 28 0.232 6 3.2
41009 81 8 20 0.233 6.39 1.6
41009 79 9 30 0.24 5.6 7.5
41017 79 10 20 0.24 5.3 7.1
41017 80 7 30 0.24 6.73 2.6

I want to get the minimum value of the "Q" column with the whole row
values, according to the "Code"  column  which is a factor. Overall it will
give me 4 rows, with the value of "Q". Below is a code that I used but it
did not give me what I wanted.

> x[which(x$Q == min(x$Q)),]

Sincerely



-- 
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] Write text file in Fortran format

2022-09-21 Thread javad bayat
Dear Rasmus;
I have no knowledge of the FORTRAN language. The text file that has been
attached is a model's output file and I know that the format is in FORTRAN.
I want to write a text file exactly similar to the attached text file using
R programming.
The steps below explain my goal:
1- Read the text file without the first 8 and last 2 rows as a dataframe.
2- Double the 3rd column values (or multiply by specific number).
3- Insert the removed first 8 rows of the original text file as header in
the dataframe.
4- Insert the removed last 2 rows of the original text file at the end of
dataframe.
5- Write the dataframe as a new text file exactly similar to the original
text file.

I have used excel but when I save it as text file, the format changes and
is not similar to the attached text file.
Sincerely

On Wed, 21 Sep 2022, 18:17 Rasmus Liland,  wrote:

> Dear Javad,
>
> Perhaps you were looking to read the
> table in Air.txt (is this Fortran
> format?) into R?
>
> b <- readLines("Air.txt")  # The text MIME attachment w/Mailman
> footer ...
> b <- b[1:(which(b=="")-1)]  # Remove the odd Mailman footer (at
> end of df)
> idx <- max(grep("^\\*", b))+1  # Start of df after header uline
> header <- tolower(strsplit(gsub("  +", "_", gsub("\\*", "",
> b[idx-2])), "_")[[1]])
> b <- read.table(text=b[-(1:idx)], header=F)
> colnames(b) <- header[header!=""]
> b <- b[,sapply(b, \(i) length(unique(i)))>1]  # Remove constant
> cols
>
> str(b)
>
> 'data.frame':   31324 obs. of  6 variables:
>  $ x   : num  583500 584000 584500 585000 585500 ...
>  $ y   : num  3018700 3018700 3018700 3018700 3018700 ...
>  $ average conc: num  32.8 33.1 33.4 33.5 33.6 ...
>  $ zelev   : num  0 0 0 0 0 0 0 0 0 0 ...
>  $ zhill   : num  0 0 0 0 0 0 0 0 0 0 ...
>  $ date(conc)  : int  16101706 16101706 16101706 16101706 16101706
> ...
>
> Best,
> Rasmus
>
> __
> 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.
>

[[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] Write text file in Fortran format

2022-09-21 Thread javad bayat
Dear all;
I apologise, I didn't know that I have to cc the list.
Thank you Mr Rui for reminding me.
Let me clarify more.
I have no knowledge of the FORTRAN language. The text file that has been
attached is a model's output file and I know that the format is in FORTRAN.
I want to write a text file exactly similar to the attached text file using
R programming.
The steps below explain my goal:
1- Read the text file without the first 8 and last 2 rows as a dataframe.
Maybe I have removed the last 2 lines, but at the end it had 2 lines
similar the first 8 lines which starts with asterisk.
2- Double the 3rd column values (or multiply by specific number).
3- Insert the removed first 8 lines of the original text file as header in
the dataframe.
4- Insert the removed last 2 lines of the original text file at the end of
dataframe.
5- Write the dataframe as a new text file exactly similar to the original
text file.

I have used excel but when I save it as text file, the format changes and
is not similar to the attached text file.
I will try all your codes in a few hours, cause I am out of office.
Sincerely yours.



On Thu, 22 Sep 2022, 04:20 Richard O'Keefe,  wrote:

> Oh, so you want to WRITE a file *like* that.
> Use ?sprintf.
> (3(1X,F13.5),3(1X,F8.2),3X,A5,2X,A8,2X,A5,5X,A8,2X,I8)
>
> Fortran sprintf
> 1X  a space
> 3X  3 spaces
> F13.5   %13.5f
> F8.2%8.2f
> A5  %5s
> A8  %8s
> I8  %8d
> 3(...)  the translation of ... written 3 times
>
> We can simplify 1X,F13.5 to F14.5
> Here's the sprintf() equivalent of the Fortran format,
> except you'll need to change the dots to spaces.
>
> "%14.5f%14.5f%14.5f%9.2f%9.2f%9.2f...%5s..%8s..%5s.%8s%10d\n
>
> On Thu, 22 Sept 2022 at 04:17, javad bayat  wrote:
>
>> Dear Rasmus;
>> I have no knowledge of the FORTRAN language. The text file that has been
>> attached is a model's output file and I know that the format is in
>> FORTRAN.
>> I want to write a text file exactly similar to the attached text file
>> using
>> R programming.
>> The steps below explain my goal:
>> 1- Read the text file without the first 8 and last 2 rows as a dataframe.
>> 2- Double the 3rd column values (or multiply by specific number).
>> 3- Insert the removed first 8 rows of the original text file as header in
>> the dataframe.
>> 4- Insert the removed last 2 rows of the original text file at the end of
>> dataframe.
>> 5- Write the dataframe as a new text file exactly similar to the original
>> text file.
>>
>> I have used excel but when I save it as text file, the format changes and
>> is not similar to the attached text file.
>> Sincerely
>>
>> On Wed, 21 Sep 2022, 18:17 Rasmus Liland,  wrote:
>>
>> > Dear Javad,
>> >
>> > Perhaps you were looking to read the
>> > table in Air.txt (is this Fortran
>> > format?) into R?
>> >
>> > b <- readLines("Air.txt")  # The text MIME attachment w/Mailman
>> > footer ...
>> > b <- b[1:(which(b=="")-1)]  # Remove the odd Mailman footer (at
>> > end of df)
>> > idx <- max(grep("^\\*", b))+1  # Start of df after header uline
>> > header <- tolower(strsplit(gsub("  +", "_", gsub("\\*", "",
>> > b[idx-2])), "_")[[1]])
>> > b <- read.table(text=b[-(1:idx)], header=F)
>> > colnames(b) <- header[header!=""]
>> > b <- b[,sapply(b, \(i) length(unique(i)))>1]  # Remove constant
>> > cols
>> >
>> > str(b)
>> >
>> > 'data.frame':   31324 obs. of  6 variables:
>> >  $ x   : num  583500 584000 584500 585000 585500 ...
>> >  $ y   : num  3018700 3018700 3018700 3018700 3018700
>> ...
>> >  $ average conc: num  32.8 33.1 33.4 33.5 33.6 ...
>> >  $ zelev   : num  0 0 0 0 0 0 0 0 0 0 ...
>> >  $ zhill   : num  0 0 0 0 0 0 0 0 0 0 ...
>> >  $ date(conc)  : int  16101706 16101706 16101706 16101706
>> 16101706
>> > ...
>> >
>> > Best,
>> > Rasmus
>> >
>> > __
>> > 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.
>> >
>>
>> [[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.
>>
>

[[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] Write text file in Fortran format

2022-09-21 Thread javad bayat
Dear all; Many thanks for your useful comments and codes.
I tried both Rui's and Jim's codes.
Jim's codes gave an error as below:
"Error in substr(inputline, 1, begincol3 - 1) :
  object 'inputline' not found"
I don't know what's wrong.
The Rui's codes worked correctly for the attached file. But I have edited
that file and removed 2 last lines from the file because I could not read
it into R.
These 2 lines were:
"
** CONCUNIT ug/m^3
** DEPUNIT g/m^2
"
When I tried to run the code for my file that has these 2 lines at the end,
it gave me this error:
"
> df1 <- read.table(text = txt_table)
Error in read.table(text = txt_table) : no lines available in input
"
The codes before the "df1 <- read.table(text = txt_table)" were run
correctly.
Sincerely



On Thu, Sep 22, 2022 at 6:58 AM javad bayat  wrote:

> Dear all;
> I apologise, I didn't know that I have to cc the list.
> Thank you Mr Rui for reminding me.
> Let me clarify more.
> I have no knowledge of the FORTRAN language. The text file that has been
> attached is a model's output file and I know that the format is in FORTRAN.
> I want to write a text file exactly similar to the attached text file using
> R programming.
> The steps below explain my goal:
> 1- Read the text file without the first 8 and last 2 rows as a dataframe.
> Maybe I have removed the last 2 lines, but at the end it had 2 lines
> similar the first 8 lines which starts with asterisk.
> 2- Double the 3rd column values (or multiply by specific number).
> 3- Insert the removed first 8 lines of the original text file as header in
> the dataframe.
> 4- Insert the removed last 2 lines of the original text file at the end of
> dataframe.
> 5- Write the dataframe as a new text file exactly similar to the original
> text file.
>
> I have used excel but when I save it as text file, the format changes and
> is not similar to the attached text file.
> I will try all your codes in a few hours, cause I am out of office.
> Sincerely yours.
>
>
>
> On Thu, 22 Sep 2022, 04:20 Richard O'Keefe,  wrote:
>
>> Oh, so you want to WRITE a file *like* that.
>> Use ?sprintf.
>> (3(1X,F13.5),3(1X,F8.2),3X,A5,2X,A8,2X,A5,5X,A8,2X,I8)
>>
>> Fortran sprintf
>> 1X  a space
>> 3X  3 spaces
>> F13.5   %13.5f
>> F8.2%8.2f
>> A5  %5s
>> A8  %8s
>> I8  %8d
>> 3(...)  the translation of ... written 3 times
>>
>> We can simplify 1X,F13.5 to F14.5
>> Here's the sprintf() equivalent of the Fortran format,
>> except you'll need to change the dots to spaces.
>>
>> "%14.5f%14.5f%14.5f%9.2f%9.2f%9.2f...%5s..%8s..%5s.%8s%10d\n
>>
>> On Thu, 22 Sept 2022 at 04:17, javad bayat  wrote:
>>
>>> Dear Rasmus;
>>> I have no knowledge of the FORTRAN language. The text file that has been
>>> attached is a model's output file and I know that the format is in
>>> FORTRAN.
>>> I want to write a text file exactly similar to the attached text file
>>> using
>>> R programming.
>>> The steps below explain my goal:
>>> 1- Read the text file without the first 8 and last 2 rows as a dataframe.
>>> 2- Double the 3rd column values (or multiply by specific number).
>>> 3- Insert the removed first 8 rows of the original text file as header in
>>> the dataframe.
>>> 4- Insert the removed last 2 rows of the original text file at the end of
>>> dataframe.
>>> 5- Write the dataframe as a new text file exactly similar to the original
>>> text file.
>>>
>>> I have used excel but when I save it as text file, the format changes and
>>> is not similar to the attached text file.
>>> Sincerely
>>>
>>> On Wed, 21 Sep 2022, 18:17 Rasmus Liland,  wrote:
>>>
>>> > Dear Javad,
>>> >
>>> > Perhaps you were looking to read the
>>> > table in Air.txt (is this Fortran
>>> > format?) into R?
>>> >
>>> > b <- readLines("Air.txt")  # The text MIME attachment w/Mailman
>>> > footer ...
>>> > b <- b[1:(which(b=="")-1)]  # Remove the odd Mailman footer (at
>>> > end of df)
>>> > idx <- max(grep("^\\*", b))+1  # Start of df after header uline
>>> > header <- tolower(strsplit(gsub("  +", "_", gsub("\\*", "",
>>> > b[idx-2])), "_")[[1]])
>>> > b <- read.table(text=b[-(1:idx)], header=F)
>>> >  

Re: [R] Write text file in Fortran format

2022-09-22 Thread javad bayat
These 2 lines were at the end of the text file, which I have attached but I
had removed them to read the text file in R.
Just like the first 8 line that start with asterisk (*).






On Thu, 22 Sep 2022, 12:21 Rui Barradas,  wrote:

> Hello,
>
> Are those lines at the begining of the file?
>
> Rui Barradas
>
> Às 06:44 de 22/09/2022, javad bayat escreveu:
> > Dear all; Many thanks for your useful comments and codes.
> > I tried both Rui's and Jim's codes.
> > Jim's codes gave an error as below:
> > "Error in substr(inputline, 1, begincol3 - 1) :
> >object 'inputline' not found"
> > I don't know what's wrong.
> > The Rui's codes worked correctly for the attached file. But I have edited
> > that file and removed 2 last lines from the file because I could not read
> > it into R.
> > These 2 lines were:
> > "
> > ** CONCUNIT ug/m^3
> > ** DEPUNIT g/m^2
> > "
> > When I tried to run the code for my file that has these 2 lines at the
> end,
> > it gave me this error:
> > "
> >> df1 <- read.table(text = txt_table)
> > Error in read.table(text = txt_table) : no lines available in input
> > "
> > The codes before the "df1 <- read.table(text = txt_table)" were run
> > correctly.
> > Sincerely
> >
> >
> >
> > On Thu, Sep 22, 2022 at 6:58 AM javad bayat 
> wrote:
> >
> >> Dear all;
> >> I apologise, I didn't know that I have to cc the list.
> >> Thank you Mr Rui for reminding me.
> >> Let me clarify more.
> >> I have no knowledge of the FORTRAN language. The text file that has been
> >> attached is a model's output file and I know that the format is in
> FORTRAN.
> >> I want to write a text file exactly similar to the attached text file
> using
> >> R programming.
> >> The steps below explain my goal:
> >> 1- Read the text file without the first 8 and last 2 rows as a
> dataframe.
> >> Maybe I have removed the last 2 lines, but at the end it had 2 lines
> >> similar the first 8 lines which starts with asterisk.
> >> 2- Double the 3rd column values (or multiply by specific number).
> >> 3- Insert the removed first 8 lines of the original text file as header
> in
> >> the dataframe.
> >> 4- Insert the removed last 2 lines of the original text file at the end
> of
> >> dataframe.
> >> 5- Write the dataframe as a new text file exactly similar to the
> original
> >> text file.
> >>
> >> I have used excel but when I save it as text file, the format changes
> and
> >> is not similar to the attached text file.
> >> I will try all your codes in a few hours, cause I am out of office.
> >> Sincerely yours.
> >>
> >>
> >>
> >> On Thu, 22 Sep 2022, 04:20 Richard O'Keefe,  wrote:
> >>
> >>> Oh, so you want to WRITE a file *like* that.
> >>> Use ?sprintf.
> >>> (3(1X,F13.5),3(1X,F8.2),3X,A5,2X,A8,2X,A5,5X,A8,2X,I8)
> >>>
> >>> Fortran sprintf
> >>> 1X  a space
> >>> 3X  3 spaces
> >>> F13.5   %13.5f
> >>> F8.2%8.2f
> >>> A5  %5s
> >>> A8  %8s
> >>> I8  %8d
> >>> 3(...)  the translation of ... written 3 times
> >>>
> >>> We can simplify 1X,F13.5 to F14.5
> >>> Here's the sprintf() equivalent of the Fortran format,
> >>> except you'll need to change the dots to spaces.
> >>>
> >>> "%14.5f%14.5f%14.5f%9.2f%9.2f%9.2f...%5s..%8s..%5s.%8s%10d\n
> >>>
> >>> On Thu, 22 Sept 2022 at 04:17, javad bayat 
> wrote:
> >>>
> >>>> Dear Rasmus;
> >>>> I have no knowledge of the FORTRAN language. The text file that has
> been
> >>>> attached is a model's output file and I know that the format is in
> >>>> FORTRAN.
> >>>> I want to write a text file exactly similar to the attached text file
> >>>> using
> >>>> R programming.
> >>>> The steps below explain my goal:
> >>>> 1- Read the text file without the first 8 and last 2 rows as a
> dataframe.
> >>>> 2- Double the 3rd column values (or multiply by specific number).
> >>>> 3- Insert the removed first 8 rows of the original text file as
> header in
> >>>> the dataframe.
> >>>> 4- Insert the removed last 2 rows of t

[R] Read Unicode text (*.txt)

2019-07-01 Thread javad bayat
Dear R users;
I am trying to read an excel CSV file (1.csv). When I read it as csv file
in R, the R shows me the exact number of row. But it puts all columns in
one column, while I have 3 or 4 columns in the data frame.
"
d4 = read.table("./4.csv",sep=";",header=TRUE)
 Warning messages:
 1: In read.table("./4.csv", sep = ";", header = TRUE) :
  line 1 appears to contain embedded nulls
 2: In read.table("./4.csv", sep = ";", header = TRUE) :
 line 2 appears to contain embedded nulls
 3: In read.table("./4.csv", sep = ";", header = TRUE) :
 line 3 appears to contain embedded nulls
 4: In read.table("./4.csv", sep = ";", header = TRUE) :
 line 4 appears to contain embedded nulls
 5: In read.table("./4.csv", sep = ";", header = TRUE) :
line 5 appears to contain embedded nulls
 6: In read.table("./4.csv", sep = ";", header = TRUE) :
line 1 appears to contain embedded nulls
 7: In scan(file = file, what = what, sep = sep, quote = quote, dec =
dec,  :
   embedded nul(s) found in input
> attach(d4)
> dim(d4)
[1] 1814394   1
"
I opened the csv file in excel and I tried to make a new csv (delimited)
file. I dont know why in the "save as type" box Unicode text (*.txt) is
written. Why the format is txt while the file extension is .CSV?
Please help me to read this format correctly.
Many thanks.



-- 
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] Read Unicode text (*.txt)

2019-07-01 Thread javad bayat
Dear all;
I use your suggestion but I gave the same warning messages. I changed the
file name (Data.csv).
"
d4<-read.csv("./Data.csv",sep=";",header=TRUE,encoding="UTF-16")
 Warning messages:
 1: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
   line 1 appears to contain embedded nulls
  2: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
  line 2 appears to contain embedded nulls
  3: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
  line 3 appears to contain embedded nulls
  4: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
   line 4 appears to contain embedded nulls
  5: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
line 5 appears to contain embedded nulls
  6: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
   line 1 appears to contain embedded nulls
  7: In scan(file = file, what = what, sep = sep, quote = quote,
dec = dec,  :
 embedded nul(s) found in input
"

I opened the Data in notepad. This is the head of Data.csv. The columns
have been separated by semicolons.
"
"INLET Time";"INLET ValueY";"TRATED WATER TANK Time";"TRATED WATER TANK
ValueY"
10/28/2018;550.057861328125;10/28/2018;487.812530517578
10/28/2018 12:00:01 ق.ظ;550.057861328125;10/28/2018 12:00:01
ق.ظ;487.812530517578
10/28/2018 12:00:02 ق.ظ;550.057861328125;10/28/2018 12:00:02
ق.ظ;487.812530517578
10/28/2018 12:00:03 ق.ظ;550.057861328125;10/28/2018 12:00:03
ق.ظ;487.812530517578
10/28/2018 12:00:04 ق.ظ;550.057861328125;10/28/2018 12:00:04
ق.ظ;487.812530517578
.
.
.
"
Thanks.



On Tue, Jul 2, 2019 at 6:14 AM Jeff Newmiller 
wrote:

> Don't be so US-centric, Abby... how do you know that javad's version of
> Excel doesn't default to using semicolons?
>
> ?read.csv2
>
> On July 1, 2019 6:06:32 PM PDT, Abby Spurdle  wrote:
> >> I am trying to read an excel CSV file (1.csv). When I read it as csv
> >file
> >> in R, the R shows me the exact number of row. But it puts all columns
> >in
> >> one column, while I have 3 or 4 columns in the data frame.
> >> d4 = read.table("./4.csv",sep=";",header=TRUE)
> >
> >Firstly, I recommend against naming your file "1.csv".
> >(Start with a letter not a number).
> >
> >Secondly, a CSV file should be separated by commas not semicolons.
> >You can specify sep=",", however, it's probably easier to use the
> >read.csv() function.
> >
> >Note that you should be able to open your file in a text editor to see
> >the
> >separators.
> >
> >> I dont know why in the "save as type" box Unicode text (*.txt)
> >
> >Other posters have suggested that you need to specify the encoding.
> >Assuming that you create your CSV file correctly in Excel, I doubt that
> >this is necessary, but I could be wrong...
> >
> >Your comment suggests that you have saved your document as "Unicode
> >text".
> >You need to tell Excel to save the file as a CSV file.
> >(There should be a list of save options).
> >
> >Simply typing a file name with a .csv file extension is unlikely to
> >produce
> >the desired result.
> >
> >   [[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.
>
> --
> Sent from my phone. Please excuse my brevity.
>


-- 
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.


[R] Problem with filling dataframe's column

2023-06-11 Thread javad bayat
Dear R users;
I am trying to fill a column based on a specific value in another column of
a dataframe, but it seems there is a problem with the codes!
The "Layer" and the "LU" are two different columns of the dataframe.
How can I fix this?
Sincerely


for (i in 1:nrow(data2$Layer)){
  if (data2$Layer == "Level 12") {
  data2$LU == "Park"
  }
  }




-- 
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] Problem with filling dataframe's column

2023-06-11 Thread javad bayat
Dear Rui;
Many thanks for your email. I used one of your codes,
"data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works
correctly for me.
Actually I need to expand the codes so as to consider all "Levels" in the
"Layer" column. There are more than hundred levels in the Layer column.
If I use your provided code, I have to write it hundred of time as below:
data2$LU[which(data2$Layer == "Level 1")] <- "Park";
data2$LU[which(data2$Layer == "Level 2")] <- "Agri";
...
...
...
.
Is there any other way to expand the code in order to consider all of the
levels simultaneously? Like the below code:
data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))] <-
c("Park", "Agri", "GS", ...)


Sincerely




On Sun, Jun 11, 2023 at 1:43 PM Rui Barradas  wrote:

> Às 21:05 de 11/06/2023, javad bayat escreveu:
> > Dear R users;
> > I am trying to fill a column based on a specific value in another column
> of
> > a dataframe, but it seems there is a problem with the codes!
> > The "Layer" and the "LU" are two different columns of the dataframe.
> > How can I fix this?
> > Sincerely
> >
> >
> > for (i in 1:nrow(data2$Layer)){
> >if (data2$Layer == "Level 12") {
> >data2$LU == "Park"
> >}
> >}
> >
> >
> >
> >
> Hello,
>
> There are two bugs in your code,
>
> 1) the index i is not used in the loop
> 2) the assignment operator is `<-`, not `==`
>
>
> Here is the loop corrected.
>
> for (i in 1:nrow(data2$Layer)){
>if (data2$Layer[i] == "Level 12") {
>  data2$LU[i] <- "Park"
>}
> }
>
>
>
> But R is a vectorized language, the following two ways are the idiomac
> ways of doing what you want to do.
>
>
>
> i <- data2$Layer == "Level 12"
> data2$LU[i] <- "Park"
>
> # equivalent one-liner
> data2$LU[data2$Layer == "Level 12"] <- "Park"
>
>
>
> If there are NA's in data2$Layer it's probably safer to use ?which() in
> the logical index, to have a numeric one.
>
>
>
> i <- which(data2$Layer == "Level 12")
> data2$LU[i] <- "Park"
>
> # equivalent one-liner
> data2$LU[which(data2$Layer == "Level 12")] <- "Park"
>
>
> Hope this helps,
>
> Rui Barradas
>


-- 
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] Problem with filling dataframe's column

2023-06-12 Thread javad bayat
Dear Rui;
Hi. I used your codes, but it seems it didn't work for me.

> pat <- c("_esmdes|_Des Section|0")
> dim(data2)
[1]  281549  9
> grep(pat, data2$Layer)
> dim(data2)
[1]  281549  9

What does grep function do? I expected the function to remove 3 rows of the
dataframe.
I do not know the reason.






On Mon, Jun 12, 2023 at 5:16 PM Rui Barradas  wrote:

> Às 23:13 de 12/06/2023, javad bayat escreveu:
> > Dear Rui;
> > Many thanks for the email. I tried your codes and found that the length
> of
> > the "Values" and "Names" vectors must be equal, otherwise the results
> will
> > not be useful.
> > For some of the characters in the Layer column that I do not need to be
> > filled in the LU column, I used "NA".
> > But I need to delete some of the rows from the table as they are useless
> > for me. I tried this code to delete entire rows of the dataframe which
> > contained these three value in the Layer column: It gave me the following
> > error.
> >
> >> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),]
> >   Warning message:
> >In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) :
> >argument 'pattern' has length > 1 and only the first element will
> be
> > used
> >
> >> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),]
> >  Warning message:
> >  In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) :
> >  argument 'pattern' has length > 1 and only the first element will be
> > used
> >
> > How can I do this?
> > Sincerely
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Sun, Jun 11, 2023 at 5:03 PM Rui Barradas 
> wrote:
> >
> >> Às 13:18 de 11/06/2023, Rui Barradas escreveu:
> >>> Às 22:54 de 11/06/2023, javad bayat escreveu:
> >>>> Dear Rui;
> >>>> Many thanks for your email. I used one of your codes,
> >>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works
> >>>> correctly for me.
> >>>> Actually I need to expand the codes so as to consider all "Levels" in
> >> the
> >>>> "Layer" column. There are more than hundred levels in the Layer
> column.
> >>>> If I use your provided code, I have to write it hundred of time as
> >> below:
> >>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park";
> >>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri";
> >>>> ...
> >>>> ...
> >>>> ...
> >>>> .
> >>>> Is there any other way to expand the code in order to consider all of
> >> the
> >>>> levels simultaneously? Like the below code:
> >>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))]
> >> <-
> >>>> c("Park", "Agri", "GS", ...)
> >>>>
> >>>>
> >>>> Sincerely
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> On Sun, Jun 11, 2023 at 1:43 PM Rui Barradas 
> >>>> wrote:
> >>>>
> >>>>> Às 21:05 de 11/06/2023, javad bayat escreveu:
> >>>>>> Dear R users;
> >>>>>> I am trying to fill a column based on a specific value in another
> >>>>>> column
> >>>>> of
> >>>>>> a dataframe, but it seems there is a problem with the codes!
> >>>>>> The "Layer" and the "LU" are two different columns of the dataframe.
> >>>>>> How can I fix this?
> >>>>>> Sincerely
> >>>>>>
> >>>>>>
> >>>>>> for (i in 1:nrow(data2$Layer)){
> >>>>>>  if (data2$Layer == "Level 12") {
> >>>>>>  data2$LU == "Park"
> >>>>>>  }
> >>>>>>  }
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>> Hello,
> >>>>>
> >>>>> There are

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread javad bayat
Dear all;
I used these codes and I get what I wanted.
Sincerely

pat = c("Level 12","Level 22","0")
data3 = data2[-which(data2$Layer == pat),]
dim(data2)
[1] 281549  9
dim(data3)
[1] 244075  9

On Tue, Jun 13, 2023 at 11:36 AM Eric Berger  wrote:

> Hi Javed,
> grep returns the positions of the matches. See an example below.
>
> > v <- c("abc", "bcd", "def")
> > v
> [1] "abc" "bcd" "def"
> > grep("cd",v)
> [1] 2
> > w <- v[-grep("cd",v)]
> > w
> [1] "abc" "def"
> >
>
>
> On Tue, Jun 13, 2023 at 8:50 AM javad bayat  wrote:
> >
> > Dear Rui;
> > Hi. I used your codes, but it seems it didn't work for me.
> >
> > > pat <- c("_esmdes|_Des Section|0")
> > > dim(data2)
> > [1]  281549  9
> > > grep(pat, data2$Layer)
> > > dim(data2)
> > [1]  281549  9
> >
> > What does grep function do? I expected the function to remove 3 rows of
> the
> > dataframe.
> > I do not know the reason.
> >
> >
> >
> >
> >
> >
> > On Mon, Jun 12, 2023 at 5:16 PM Rui Barradas 
> wrote:
> >
> > > Às 23:13 de 12/06/2023, javad bayat escreveu:
> > > > Dear Rui;
> > > > Many thanks for the email. I tried your codes and found that the
> length
> > > of
> > > > the "Values" and "Names" vectors must be equal, otherwise the results
> > > will
> > > > not be useful.
> > > > For some of the characters in the Layer column that I do not need to
> be
> > > > filled in the LU column, I used "NA".
> > > > But I need to delete some of the rows from the table as they are
> useless
> > > > for me. I tried this code to delete entire rows of the dataframe
> which
> > > > contained these three value in the Layer column: It gave me the
> following
> > > > error.
> > > >
> > > >> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),]
> > > >   Warning message:
> > > >In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) :
> > > >    argument 'pattern' has length > 1 and only the first element
> will
> > > be
> > > > used
> > > >
> > > >> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),]
> > > >  Warning message:
> > > >  In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) :
> > > >  argument 'pattern' has length > 1 and only the first element
> will be
> > > > used
> > > >
> > > > How can I do this?
> > > > Sincerely
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On Sun, Jun 11, 2023 at 5:03 PM Rui Barradas 
> > > wrote:
> > > >
> > > >> Às 13:18 de 11/06/2023, Rui Barradas escreveu:
> > > >>> Às 22:54 de 11/06/2023, javad bayat escreveu:
> > > >>>> Dear Rui;
> > > >>>> Many thanks for your email. I used one of your codes,
> > > >>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it
> works
> > > >>>> correctly for me.
> > > >>>> Actually I need to expand the codes so as to consider all
> "Levels" in
> > > >> the
> > > >>>> "Layer" column. There are more than hundred levels in the Layer
> > > column.
> > > >>>> If I use your provided code, I have to write it hundred of time as
> > > >> below:
> > > >>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park";
> > > >>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri";
> > > >>>> ...
> > > >>>> ...
> > > >>>> ...
> > > >>>> .
> > > >>>> Is there any other way to expand the code in order to consider
> all of
> > > >> the
> > > >>>> levels simultaneously? Like the below code:
> > > >>>> data2$LU[which(data2$La

[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.


[R] Volume of polygon

2023-12-05 Thread javad bayat
 Dear all;
I am trying to calculate the volume of a polygon shapefile according to a
DEM raster. I have provided some codes at the end of this email.I dont know
if the codes are correct or not. Following this, I have another question
too.
I want to know if the volume of the reservoir rises or doubles, what would
be the elevation?
I would be more than happy if anyone could help me.
Sincerely

"
library(raster)
library(terra)
library(exactextractr)
library(dplyr)
library(sf)
r <- raster("Base.tif")
p <- shapefile("p.shp")
r <- crop(r, p)
r <- mask(r, p)
x <- exact_extract(r, p, coverage_area = TRUE)

x1 = as.data.frame(x[1])
head(x1)
x1 = na.omit(x1)

x1$Height = max(x1[,1]) - x1[,1]

x1$Vol = x1[,2] * x1[,3]

sum(x1$Vol)

"

-- 
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] Volume of polygon

2023-12-05 Thread javad bayat
Dear Bert;
Thank you for your reply. The reservoir is not cylindrica. This is the
table I have created from the data extracted.
Maybe there is a way to get the relation between Elevation, Area and Volume
to get the elevation at a specific Volume.
Sincerely

valueArea   Height  Vol
3   2183  89.52593125 11190.74
5   2181  98.92991127 12564.10
6   2180 154.64484128 19794.54
7   2181 123.92825127 15738.89
9   2183  82.42211125 10302.76
10  2183 150.12180125 18765.23

On Wed, Dec 6, 2023 at 8:39 AM Bert Gunter  wrote:

> The volume of a polygon  = 0.  Polyhedra  have volumes.
>
> This may be irrelevant, but if the lake is cylindrical == constant cross
> sectional area at all depths, then height doubles when the volume does and
> vice versa.  Otherwise you have to know how area varies with height or use
> more sensible approximations thereto.
>
> Cheers,
> Bert
>
> On Tue, Dec 5, 2023, 20:13 javad bayat  wrote:
>
>>  Dear all;
>> I am trying to calculate the volume of a polygon shapefile according to a
>> DEM raster. I have provided some codes at the end of this email.I dont
>> know
>> if the codes are correct or not. Following this, I have another question
>> too.
>> I want to know if the volume of the reservoir rises or doubles, what would
>> be the elevation?
>> I would be more than happy if anyone could help me.
>> Sincerely
>>
>> "
>> library(raster)
>> library(terra)
>> library(exactextractr)
>> library(dplyr)
>> library(sf)
>> r <- raster("Base.tif")
>> p <- shapefile("p.shp")
>> r <- crop(r, p)
>> r <- mask(r, p)
>> x <- exact_extract(r, p, coverage_area = TRUE)
>>
>> x1 = as.data.frame(x[1])
>> head(x1)
>> x1 = na.omit(x1)
>>
>> x1$Height = max(x1[,1]) - x1[,1]
>>
>> x1$Vol = x1[,2] * x1[,3]
>>
>> sum(x1$Vol)
>>
>> "
>>
>> --
>> 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.
>>
>

-- 
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.


[R] Linear model and approx function

2023-12-09 Thread javad bayat
Dear all;

I have a dataframe with several columns. The columns are the elevation,
volume  and the area of the cells (which were placed inside a polygon). I
have extracted them from DEM raster to calculate the volume under polygon
and the elevation for a specific volume of the reservoir.

> head(x6,2)
  Elevation   Vol  Area V_sum  A_sum
1 2145  13990.38  85.83053  13990.38   85.83053
2 2147  43129.18 267.88312  57119.56  353.71365

> tail(x6,2)
 Elevation  Vol  Area  V_sumA_sum
158  2307 233.0276 233.02756 1771806968 15172603
159  2308   0.  71.65642 1771806968 15172674

I used a linear model to estimate the elevation for a specific volume, but
the codes do not work properly.

lm1 = lm(x6[,1]~x6[,4])
new_volume <- 3,000,000,000
pred_elev <- predict(lm1, newdata = data.frame(volume = new_volume))
pred_elev

The results just estimated for the 159 rows of the dataframe, not the new
volume.

> tail(pred_elev)
 154  155  156  157  158  159
2254.296 2254.296 2254.296 2254.296 2254.296 2254.296

Also I have used the approx function, but it does not work for the new
volume, too.

> a = x6[,1]
> b = x6[,4]
> estimate <- 3,000,000,000
> appro <- approx(b,a, xout = estimate)
> appro
$x
[1] 3e+09

$y
[1] NA

I do not know why it has happened.

Is there any way to do this?
Or maybe there is another way to do that.
I would be more than happy if anyone help me.

Sincerely

[[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] Problem when trying to install packages

2024-03-15 Thread javad bayat
'Content
> type 'application/x-gzip' length 1292936 bytes (1.2 MB)downloaded 1.2
> MB
> trying URL '
https://cran.rstudio.com/src/contrib/lubridate_1.9.3.tar.gz'Content
> type 'application/x-gzip' length 428043 bytes (418 KB)downloaded 418
> KB
> trying URL '
https://cran.rstudio.com/src/contrib/mapproj_1.2.11.tar.gz'Content
> type 'application/x-gzip' length 25544 bytes (24 KB)downloaded 24 KB
> trying URL 'https://cran.rstudio.com/src/contrib/mgcv_1.9-1.tar.gz'Content
> type 'application/x-gzip' length 1083217 bytes (1.0 MB)downloaded 1.0
> MB
> trying URL '
https://cran.rstudio.com/src/contrib/purrr_1.0.2.tar.gz'Content
> type 'application/x-gzip' length 220868 bytes (215 KB)downloaded 215
> KB
> trying URL '
https://cran.rstudio.com/src/contrib/openair_2.18-2.tar.gz'Content
> type 'application/x-gzip' length 1796725 bytes (1.7 MB)downloaded 1.7
Hello,

If you are on Windows, do you have rtools [1] installed?




On Thu, Mar 14, 2024 at 6:47 PM Rui Barradas  wrote:

> Às 04:12 de 13/03/2024, javad bayat escreveu:
> > Dear Rui;
> > I hope this email finds you well. I have a problem installing packages in
> > Rstudio and R software. When I try to install a package, the software
> tries
> > to download but after downloading, it gives some errors and does not
> work.
> > I would be more than happy if you please help me to solve this issue.
> > Warm regards.
> >
> >
> >> install.packages("openair", type = "source")Installing package into
> ‘C:/R_Libs’
> > (as ‘lib’ is unspecified)Warning in install.packages :
> >dependencies ‘lattice’, ‘MASS’ are not availablealso installing the
> > dependencies ‘deldir’, ‘RcppEigen’, ‘cli’, ‘glue’, ‘lifecycle’,
> > ‘pillar’, ‘rlang’, ‘tibble’, ‘tidyselect’, ‘vctrs’, ‘png’, ‘jpeg’,
> > ‘interp’, ‘timechange’, ‘maps’, ‘nlme’, ‘Matrix’, ‘cluster’, ‘dplyr’,
> > ‘hexbin’, ‘latticeExtra’, ‘lubridate’, ‘mapproj’, ‘mgcv’, ‘purrr’
> > trying URL '
> https://cran.rstudio.com/src/contrib/deldir_2.0-4.tar.gz'Content
> > type 'application/x-gzip' length 103621 bytes (101 KB)downloaded 101
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/RcppEigen_0.3.4.0.0.tar.gz'Content
> > type 'application/x-gzip' length 1765714 bytes (1.7 MB)downloaded 1.7
> > MB
> > trying URL '
> https://cran.rstudio.com/src/contrib/cli_3.6.2.tar.gz'Content
> > type 'application/x-gzip' length 569771 bytes (556 KB)downloaded 556
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/glue_1.7.0.tar.gz'Content
> > type 'application/x-gzip' length 105420 bytes (102 KB)downloaded 102
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/lifecycle_1.0.4.tar.gz'Content
> > type 'application/x-gzip' length 107656 bytes (105 KB)downloaded 105
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/pillar_1.9.0.tar.gz'Content
> > type 'application/x-gzip' length 444528 bytes (434 KB)downloaded 434
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/rlang_1.1.3.tar.gz'Content
> > type 'application/x-gzip' length 763765 bytes (745 KB)downloaded 745
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/tibble_3.2.1.tar.gz'Content
> > type 'application/x-gzip' length 565982 bytes (552 KB)downloaded 552
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/tidyselect_1.2.1.tar.gz'Content
> > type 'application/x-gzip' length 103591 bytes (101 KB)downloaded 101
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/vctrs_0.6.5.tar.gz'Content
> > type 'application/x-gzip' length 969066 bytes (946 KB)downloaded 946
> > KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/png_0.1-8.tar.gz'Content
> > type 'application/x-gzip' length 24880 bytes (24 KB)downloaded 24 KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/jpeg_0.1-10.tar.gz'Content
> > type 'application/x-gzip' length 18667 bytes (18 KB)downloaded 18 KB
> > trying URL '
> https://cran.rstudio.com/src/contrib/interp_1.1-6.tar.gz'Content
> > type 'application/x-gzip' length 1112116 bytes (1.1 MB)downloaded 1.1
> > MB
> > trying URL '
> https://cran.rstudio.com/src/contrib/timechange_0.3.0.tar.gz'Content
> > type 'application/x-gzip' length 103439 bytes (101 K

Re: [R] Problem when trying to install packages

2024-03-16 Thread javad bayat
Dear all;
I found a useful video on youtube that has explained how to install Rtools.
I followed the instructions and the problem was solved.
" Installing R version 4.0 + RTools 4.0 + RStudio For Data Science (#R
#RTools #RStudio #DataScience) - YouTube
<https://www.youtube.com/watch?v=h2IPWVXaUuU> "
Sincerely

On Sat, Mar 16, 2024 at 10:15 AM Bert Gunter  wrote:

> Though Navigator may mess up any Rtools stuff because it handles the
> directory trees where packages and dependencies are located, does it not?
> If so, maybe just reinstall RStudio directly from its website to proceed.
> Just a guess obviously.
>
> Bert
>
> On Sat, Mar 16, 2024, 05:09 javad bayat  wrote:
>
>>  Dear Rui;
>> Many thanks for your reply. I have installed Rtools (rtools43-5958-5975)
>> on
>> my PC and I have R version 4.3.3 and 4.3.2 to install. Also I have
>> installed Rstudio through Anaconda Navigator.
>> But I do not know how to use Rtools for installing the R packages. I would
>> be more than happy if you help me.
>> Sincerely yours
>>
>>
>>
>> > Dear Rui;
>> > I hope this email finds you well. I have a problem installing packages
>> in
>> > Rstudio and R software. When I try to install a package, the software
>> tries
>> > to download but after downloading, it gives some errors and does not
>> work.
>> > I would be more than happy if you please help me to solve this issue.
>> > Warm regards.
>> >
>> >
>> >> install.packages("openair", type = "source")Installing package into
>> ‘C:/R_Libs’
>> > (as ‘lib’ is unspecified)Warning in install.packages :
>> >dependencies ‘lattice’, ‘MASS’ are not availablealso installing the
>> > dependencies ‘deldir’, ‘RcppEigen’, ‘cli’, ‘glue’, ‘lifecycle’,
>> > ‘pillar’, ‘rlang’, ‘tibble’, ‘tidyselect’, ‘vctrs’, ‘png’, ‘jpeg’,
>> > ‘interp’, ‘timechange’, ‘maps’, ‘nlme’, ‘Matrix’, ‘cluster’, ‘dplyr’,
>> > ‘hexbin’, ‘latticeExtra’, ‘lubridate’, ‘mapproj’, ‘mgcv’, ‘purrr’
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/deldir_2.0-4.tar.gz'Content
>> > type 'application/x-gzip' length 103621 bytes (101 KB)downloaded 101
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/RcppEigen_0.3.4.0.0.tar.gz'Content
>> > type 'application/x-gzip' length 1765714 bytes (1.7 MB)downloaded 1.7
>> > MB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/cli_3.6.2.tar.gz'Content
>> > type 'application/x-gzip' length 569771 bytes (556 KB)downloaded 556
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/glue_1.7.0.tar.gz'Content
>> > type 'application/x-gzip' length 105420 bytes (102 KB)downloaded 102
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/lifecycle_1.0.4.tar.gz'Content
>> > type 'application/x-gzip' length 107656 bytes (105 KB)downloaded 105
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/pillar_1.9.0.tar.gz'Content
>> > type 'application/x-gzip' length 444528 bytes (434 KB)downloaded 434
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/rlang_1.1.3.tar.gz'Content
>> > type 'application/x-gzip' length 763765 bytes (745 KB)downloaded 745
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/tibble_3.2.1.tar.gz'Content
>> > type 'application/x-gzip' length 565982 bytes (552 KB)downloaded 552
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/tidyselect_1.2.1.tar.gz'Content
>> > type 'application/x-gzip' length 103591 bytes (101 KB)downloaded 101
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/vctrs_0.6.5.tar.gz'Content
>> > type 'application/x-gzip' length 969066 bytes (946 KB)downloaded 946
>> > KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/png_0.1-8.tar.gz'Content
>> > type 'application/x-gzip' length 24880 bytes (24 KB)downloaded 24 KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/jpeg_0.1-10.tar.gz'Content
>> > type 'application/x-gzip' length 18667 bytes (18 KB)downloaded 18 KB
>> > trying URL '
>> https://cran.rstudio.com/src/contrib/interp_1.1-6.tar.gz'Content
>> > type 'application/x-gzip' l

[R] Question regarding reservoir volume and water level

2024-04-07 Thread javad bayat
Dear all;
I have a question about the water level of a reservoir, when the volume
changed or doubled.
There is a DEM file with the highest elevation 1267 m. The lowest elevation
is 1230 m. The current volume of the reservoir is 7,000,000 m3 at 1240 m.
Now I want to know what would be the water level if the volume rises to
1250 m? or what would be the water level if the volume doubled (14,000,000
m3)?

Is there any way to write codes to do this in R?
I would be more than happy if anyone could help me.
Sincerely








-- 
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] Question regarding reservoir volume and water level

2024-04-07 Thread javad bayat
Dear all;
Many thanks for your replies. This was not homework. I apologize.
Let me explain more.
There is a dam constructed in a valley with the highest elevation of 1255
m. The area of its reservoir can be calculated by drawing a polygon around
the water and it is known.
I have the Digital Elevation Model (DEM) of the region (reservoir and its
surrounding area). I have calculated the volume of the current reservoir
(7e6 m3) using the following codes.
library(raster)
library(terra)
library(exactextractr)
library(dplyr)
library(sf)
# Calculate volume for polygon
# Read the DEM raster file
r <- rast("E:/...DEM.tif")
# Read the polygon shapefile
p <- st_read("E:/...Dam.shp")

r <- crop(r, extent(p))
r <- mask(r, p)

# Extract the cells in each polygon and calculate the area of each cell
x <- exact_extract(r, p, coverage_area = TRUE)
# Extract polygon values as a dataframe
x1 = as.data.frame(x[1])
head(x1)
x1 = na.omit(x1)
# Calculate the height above the minimum elevation in the polygon
x1$Height = max(x1[,1]) - x1[,1]
# Calculate the volume of each cell
x1$Vol = x1[,2] * x1[,3]
sum(x1$Vol)
x2 = x1[,c(1,2,4)]
x2 = sort(x2,'value')
head(x2)
x3 <- aggregate(Vol ~ value, data = x2, FUN = sum)
x4 <- aggregate(coverage_area ~ value, data = x2, FUN = sum)
x5 = cbind(x3, Area = x4[,2])
library(dplyr)
x6 <- x5 %>%
  mutate(V_sum = cumsum(Vol)) %>%
  mutate(A_sum = cumsum(Area))
plot(x6$value~x6$V_sum)

And I thought that it is possible to get the elevation for a specific
volume by linear model between elevation and volume, as follow:

# Get a linear model between elevation and the volume
lm1 <- lm(value ~ V_sum, data = x6)
d <- data.frame(V_sum = 14e6)  #
predict(lm1, newdata = d)

But it is not possible through the LM.
Now I want to know what would be the water level in the reservoir if the
reservoir volume doubled or we adding a known volume to it?
Also what would be the volume if the water level increases to 1250 m?

I would be more than happy if you help me to do this.
Sincerely

On Mon, Apr 8, 2024 at 12:23 AM  wrote:

> John,
>
> Your reaction was what my original reaction was until I realized I had to
> find out what a DEM file was and that contains enough of the kind of
> depth-dimension data you describe albeit what may be a very irregular cross
> section to calculate for areas and thence volumes.
>
> If I read it correctly, this can be a very real-world problem worthy of a
> solution, such as in places like California where they had a tad more rain
> than usual and some reservoirs may overflow. Someone else provided what
> sounds like a mathematical algorithm but my guess is what is needed here is
> perhaps less analytic since there may be no trivial way to create formulas
> and take integrals and so on, but simply an approximate way to calculate
> incremental volumes for each horizontal "slice" and keep adding or
> subtracting them till you reach a target and then read off another variable
> at that point such as depth.
>
> Some care must be taken as water level has to be relative to something and
> many natural reservoirs have no unique bottom level. Some water may also be
> stored underground and to the side and pour in if the level lowers or can
> be
> used to escape if the level rises.
>
>
> -Original Message-
> From: R-help  On Behalf Of Sorkin, John
> Sent: Sunday, April 7, 2024 3:08 PM
> To: Rui Barradas ; javad bayat  >;
> R-help 
> Subject: Re: [R] Question regarding reservoir volume and water level
>
> Aside from the fact that the original question might well be a class
> exercise (or homework), the question is unanswerable given the data given
> by
> the original poster. One needs to know the dimensions of the reservoir,
> above and below the current waterline. Are the sides, above and below the
> waterline smooth? Is the region currently above the waterline that can
> store
> water a mirror image of the region below the waterline? Is the region above
> the reservoir include a flood plane? Will the additional water go into the
> flood plane?
>
> The lack of required detail in the question posed by the original poster
> suggests that there are strong assumptions, assumptions that typically
> would
> be made in a class-room example or exercise.
>
> John
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine, University of Maryland School of Medicine;
> Associate Director for Biostatistics and Informatics, Baltimore VA Medical
> Center Geriatrics Research, Education, and Clinical Center;
> PI Biostatistics and Informatics Core, University of Maryland School of
> Medicine Claude D. Pepper Older Americans Independence Center;
> Senior Statistician University of Maryland Center for Vascular Research;
>
> Division of Gerontology and Paliat

Re: [R] Question regarding reservoir volume and water level

2024-04-10 Thread javad bayat
Dear all;
Thank you for your reply.
David has explained an interesting method.
David I have DEM file of the region and I have extracted the xyz data from
that.
Also I can extract bathymetry data as xyz file.
I have calculated the storage (volume) of reservoir at the current
elevation.
But the method I have used to calculate the volume is different from your
method. I have crop DEM by the reservoir boundary and then calculate the
volume.
I would be more than happy if you please please explain more or write codes
for me how to get volume at different elevation.
And also about the following function, especially f(Storage).

lm(Elevation~f(Storage)
Sincerely

On Tue, 9 Apr 2024, 21:26 David Stevens via R-help, 
wrote:

> Water engineer here. The standard approach is to 1) get the storage vs.
> elevation data from the designers of the reservoir or, barring that, 2)
> get the bathymetry data from USBR or state DWR, or, if available, get
> the DEM data from USGS if the survey was done before the reservoir was
> built or 3) get a boat+sonar with GPS  +lots of time and survey the
> bottom elevation yourself. Put the xyz data into ArcGIS and have it
> create the bottom surface, then, with several elevations, integrate the
> xyz data from Z to the bottom to find the storage. Plot the storage at
> each water surface to get an idea of the shape and then use
> lm(Elevation~f(Storage) where f(Storage) may be a cubic or quartic
> polynomial. Then double the Storage and calculate Elevation. This type
> of thing is done everyday by hydrologists.
>
> Good luck
>
> David K Stevens, PhD, PE, Professor
> Civil and Environmental Engineering
> Utah Water Research Laboratory
> Utah State University
> 8200 Old Main Hill
> Logan, UT 84322-8200
> david.stev...@usu.edu
> (435) 797-3229 (office)
>
> On 4/9/2024 8:01 AM, peter dalgaard wrote:
> > So, you know how to get volume for given water level.
> >
> > For the reverse problem, you get in trouble because of the nonlinearity
> inherent in the dependence of surface area on the level.
> >
> > I don't think there is a simple solution to this, save for mapping out
> the volume as a function of water level and solving equations for the water
> level using (say) uniroot(). Which may actually suffice for practical
> purposes.
> >
> > For small changes, finding the derivative of the relation is easy:
> d(volume) = Area * d(level) and this can be used as an approximate relation
> as long as the Area remains nearly constant.
> >
> > However generic questions like doubling the volume are impossible to
> answer without knowledge of the reservoir shape. E.g. in a cylindrical
> reservoir halving the water level also halves the volume, but in a conical
> reservoir, halving the level leaves only 1/8 of the volume.
> >
> > -pd
> >
> >
> >
> >> On 8 Apr 2024, at 05:55 , javad bayat  wrote:
> >>
> >> Dear all;
> >> Many thanks for your replies. This was not homework. I apologize.
> >> Let me explain more.
> >> There is a dam constructed in a valley with the highest elevation of
> 1255
> >> m. The area of its reservoir can be calculated by drawing a polygon
> around
> >> the water and it is known.
> >> I have the Digital Elevation Model (DEM) of the region (reservoir and
> its
> >> surrounding area). I have calculated the volume of the current reservoir
> >> (7e6 m3) using the following codes.
> >> library(raster)
> >> library(terra)
> >> library(exactextractr)
> >> library(dplyr)
> >> library(sf)
> >> # Calculate volume for polygon
> >> # Read the DEM raster file
> >> r <- rast("E:/...DEM.tif")
> >> # Read the polygon shapefile
> >> p <- st_read("E:/...Dam.shp")
> >>
> >> r <- crop(r, extent(p))
> >> r <- mask(r, p)
> >>
> >> # Extract the cells in each polygon and calculate the area of each cell
> >> x <- exact_extract(r, p, coverage_area = TRUE)
> >> # Extract polygon values as a dataframe
> >> x1 = as.data.frame(x[1])
> >> head(x1)
> >> x1 = na.omit(x1)
> >> # Calculate the height above the minimum elevation in the polygon
> >> x1$Height = max(x1[,1]) - x1[,1]
> >> # Calculate the volume of each cell
> >> x1$Vol = x1[,2] * x1[,3]
> >> sum(x1$Vol)
> >> x2 = x1[,c(1,2,4)]
> >> x2 = sort(x2,'value')
> >> head(x2)
> >> x3 <- aggregate(Vol ~ value, data = x2, FUN = sum)
> >> x4 <- aggregate(coverage_area ~ value, data = x2, FUN = sum)
> >> x5 = cbind(x3, Area = x4[,2])
> >>

[R] Reminder: Question regarding reservoir volume and water level

2024-04-15 Thread javad bayat
On Wed, Apr 10, 2024 at 11:05 PM javad bayat  wrote:

> Dear all;
> Thank you for your reply.
> David has explained an interesting method.
> David I have DEM file of the region and I have extracted the xyz data from
> that.
> Also I can extract bathymetry data as xyz file.
> I have calculated the storage (volume) of reservoir at the current
> elevation.
> But the method I have used to calculate the volume is different from your
> method. I have crop DEM by the reservoir boundary and then calculate the
> volume.
> I would be more than happy if you please please explain more or write
> codes for me how to get volume at different elevation.
> And also about the following function, especially f(Storage).
>
> lm(Elevation~f(Storage)
> Sincerely
>
> On Tue, 9 Apr 2024, 21:26 David Stevens via R-help, 
> wrote:
>
>> Water engineer here. The standard approach is to 1) get the storage vs.
>> elevation data from the designers of the reservoir or, barring that, 2)
>> get the bathymetry data from USBR or state DWR, or, if available, get
>> the DEM data from USGS if the survey was done before the reservoir was
>> built or 3) get a boat+sonar with GPS  +lots of time and survey the
>> bottom elevation yourself. Put the xyz data into ArcGIS and have it
>> create the bottom surface, then, with several elevations, integrate the
>> xyz data from Z to the bottom to find the storage. Plot the storage at
>> each water surface to get an idea of the shape and then use
>> lm(Elevation~f(Storage) where f(Storage) may be a cubic or quartic
>> polynomial. Then double the Storage and calculate Elevation. This type
>> of thing is done everyday by hydrologists.
>>
>> Good luck
>>
>> David K Stevens, PhD, PE, Professor
>> Civil and Environmental Engineering
>> Utah Water Research Laboratory
>> Utah State University
>> 8200 Old Main Hill
>> Logan, UT 84322-8200
>> david.stev...@usu.edu
>> (435) 797-3229 (office)
>>
>> On 4/9/2024 8:01 AM, peter dalgaard wrote:
>> > So, you know how to get volume for given water level.
>> >
>> > For the reverse problem, you get in trouble because of the nonlinearity
>> inherent in the dependence of surface area on the level.
>> >
>> > I don't think there is a simple solution to this, save for mapping out
>> the volume as a function of water level and solving equations for the water
>> level using (say) uniroot(). Which may actually suffice for practical
>> purposes.
>> >
>> > For small changes, finding the derivative of the relation is easy:
>> d(volume) = Area * d(level) and this can be used as an approximate relation
>> as long as the Area remains nearly constant.
>> >
>> > However generic questions like doubling the volume are impossible to
>> answer without knowledge of the reservoir shape. E.g. in a cylindrical
>> reservoir halving the water level also halves the volume, but in a conical
>> reservoir, halving the level leaves only 1/8 of the volume.
>> >
>> > -pd
>> >
>> >
>> >
>> >> On 8 Apr 2024, at 05:55 , javad bayat  wrote:
>> >>
>> >> Dear all;
>> >> Many thanks for your replies. This was not homework. I apologize.
>> >> Let me explain more.
>> >> There is a dam constructed in a valley with the highest elevation of
>> 1255
>> >> m. The area of its reservoir can be calculated by drawing a polygon
>> around
>> >> the water and it is known.
>> >> I have the Digital Elevation Model (DEM) of the region (reservoir and
>> its
>> >> surrounding area). I have calculated the volume of the current
>> reservoir
>> >> (7e6 m3) using the following codes.
>> >> library(raster)
>> >> library(terra)
>> >> library(exactextractr)
>> >> library(dplyr)
>> >> library(sf)
>> >> # Calculate volume for polygon
>> >> # Read the DEM raster file
>> >> r <- rast("E:/...DEM.tif")
>> >> # Read the polygon shapefile
>> >> p <- st_read("E:/...Dam.shp")
>> >>
>> >> r <- crop(r, extent(p))
>> >> r <- mask(r, p)
>> >>
>> >> # Extract the cells in each polygon and calculate the area of each cell
>> >> x <- exact_extract(r, p, coverage_area = TRUE)
>> >> # Extract polygon values as a dataframe
>> >> x1 = as.data.frame(x[1])
>> >> head(x1)
>> >> x1 = na.omit(x1)
>> >> # Calculate the height a

[R] Converting .grib to excel file

2024-06-25 Thread javad bayat
Dear all;
I have downloaded meteorology data from "
https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=form";
as .grib format. It has hourly data of a complete year (every hour of every
day of 12 months) and has 6 meteorology parameters. The file has been
attached.
I am trying to convert it to an excel file that puts every parameter in a
separated column. For instance, the first col represents Date, 2nd
represents Temperature and so on.
Is there any way to do it?
I used these codes but did not work:
# install.packages("rNOMADS")

library(rNOMADS)

# Read GRIB data
grib_data <- ReadGrib("C:/Users/admin/Downloads/Met.grib")

# Convert to a data frame
grib_df <- as.data.frame(grib_data)

# Write the data frame to a CSV file
write.csv(grib_df, file = "output.csv")


I would be more than happy if anyone could help me.
Sincerely

-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Alternative Mail: bayat...@yahoo.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.


Re: [R] Converting .grib to excel file

2024-06-25 Thread javad bayat
Richard,
Many thanks for your email.
I had attached the grib file to the original email to R help team but it
seems you did not receive it.
Unfortunately, I do not know how to reduce the volume or extract some of
the grib file data to send it for you. The file has the volume of 6
Megabyte.
I can send it by email.
The file has 6 met parameters and Date (day/month/year hour:minute).
I want the exported file as excel contains 7 columns (Date + 6 met
parameters).


On Tue, 25 Jun 2024, 15:54 Richard O'Keefe,  wrote:

> Your message referred to an attached file but there was no attachment,
> I have no account at that service, so could not download a sample for
> myself.  Does the licence for the data even allow you to send some of
> it in a message?  Which parameters are you extracting?  When you say
> "it didn't work", what actually happened?  Which step went wrong and how?
>
>
> On Tue, 25 Jun 2024 at 20:33, javad bayat  wrote:
> >
> > Dear all;
> > I have downloaded meteorology data from "
> >
> https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=form
> "
> > as .grib format. It has hourly data of a complete year (every hour of
> every
> > day of 12 months) and has 6 meteorology parameters. The file has been
> > attached.
> > I am trying to convert it to an excel file that puts every parameter in a
> > separated column. For instance, the first col represents Date, 2nd
> > represents Temperature and so on.
> > Is there any way to do it?
> > I used these codes but did not work:
> > # install.packages("rNOMADS")
> >
> > library(rNOMADS)
> >
> > # Read GRIB data
> > grib_data <- ReadGrib("C:/Users/admin/Downloads/Met.grib")
> >
> > # Convert to a data frame
> > grib_df <- as.data.frame(grib_data)
> >
> > # Write the data frame to a CSV file
> > write.csv(grib_df, file = "output.csv")
> >
> >
> > I would be more than happy if anyone could help me.
> > Sincerely
> >
> > --
> > Best Regards
> > Javad Bayat
> > M.Sc. Environment Engineering
> > Alternative Mail: bayat...@yahoo.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.
>

[[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] Converting .grib to excel file

2024-06-25 Thread javad bayat
Dear Bert and Sara;
I have searched on the internet and found some way to do this like python.
But python is so complicated to me as it needs many steps to be done for
reading and converting it.
I will try terra package to convert it.


On Tue, 25 Jun 2024, 15:15 javad bayat,  wrote:

> Richard,
> Many thanks for your email.
> I had attached the grib file to the original email to R help team but it
> seems you did not receive it.
> Unfortunately, I do not know how to reduce the volume or extract some of
> the grib file data to send it for you. The file has the volume of 6
> Megabyte.
> I can send it by email.
> The file has 6 met parameters and Date (day/month/year hour:minute).
> I want the exported file as excel contains 7 columns (Date + 6 met
> parameters).
>
>
> On Tue, 25 Jun 2024, 15:54 Richard O'Keefe,  wrote:
>
>> Your message referred to an attached file but there was no attachment,
>> I have no account at that service, so could not download a sample for
>> myself.  Does the licence for the data even allow you to send some of
>> it in a message?  Which parameters are you extracting?  When you say
>> "it didn't work", what actually happened?  Which step went wrong and how?
>>
>>
>> On Tue, 25 Jun 2024 at 20:33, javad bayat  wrote:
>> >
>> > Dear all;
>> > I have downloaded meteorology data from "
>> >
>> https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=form
>> "
>> > as .grib format. It has hourly data of a complete year (every hour of
>> every
>> > day of 12 months) and has 6 meteorology parameters. The file has been
>> > attached.
>> > I am trying to convert it to an excel file that puts every parameter in
>> a
>> > separated column. For instance, the first col represents Date, 2nd
>> > represents Temperature and so on.
>> > Is there any way to do it?
>> > I used these codes but did not work:
>> > # install.packages("rNOMADS")
>> >
>> > library(rNOMADS)
>> >
>> > # Read GRIB data
>> > grib_data <- ReadGrib("C:/Users/admin/Downloads/Met.grib")
>> >
>> > # Convert to a data frame
>> > grib_df <- as.data.frame(grib_data)
>> >
>> > # Write the data frame to a CSV file
>> > write.csv(grib_df, file = "output.csv")
>> >
>> >
>> > I would be more than happy if anyone could help me.
>> > Sincerely
>> >
>> > --
>> > Best Regards
>> > Javad Bayat
>> > M.Sc. Environment Engineering
>> > Alternative Mail: bayat...@yahoo.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.
>>
>

[[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] Converting .grib to excel file

2024-06-26 Thread javad bayat
Dear all;
I used the terra package to export .grib data as an excel file but I could
not do it.
The grib file is readed and converted to raster correctly. It contains
hourly data of a complete year for 6 met parameters (365 * 24 * 6 =
52,560). In the "raster_data" it can be seen as "nlyr" ( dimensions  : 1,
1, 52560  (nrow, ncol, nlyr) ).
It also contains the Date values which start from 01/01/2019 00:00 to
31/12/2019 23:00.
What I am trying to do is:
Export the data as an Excel file, ensuring that the met parameters are
placed in separate columns and sorted from the first hour on the first day
to the end of the date (31/12/2019 23:00).
Here are the codes:

> library(terra)
> grib_file <- "C:/Users/admin/Downloads/Met.grib"
> raster_data <- rast(grib_file)
> raster_data
class   : SpatRaster
dimensions  : 1, 1, 52560  (nrow, ncol, nlyr)
resolution  : 0.25, 0.25  (x, y)
extent  : 49.725, 49.975, 33.965, 34.215  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat Coordinate System imported from GRIB file
source  : Met.grib
names   : SFC (~[m/s], SFC (~[m/s], SFC (~e [C], SFC (~ [Pa], SFC (~)
[-], SFC (~n [m], ...
unit: m/s, m/s,   C,  Pa,
-,   m, ...
time: 2019-01-01 to 2019-12-31 23:00:00 UTC

> raster_data[[1]]
class   : SpatRaster
dimensions  : 1, 1, 1  (nrow, ncol, nlyr)
resolution  : 0.25, 0.25  (x, y)
extent  : 49.725, 49.975, 33.965, 34.215  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat Coordinate System imported from GRIB file
source  : Met.grib
name: SFC (Ground or water surface); 10 metre u wind component
[m/s]
unit:
 m/s
time: 2019-01-01 UTC

> raster_data[[52560]]
class   : SpatRaster
dimensions  : 1, 1, 1  (nrow, ncol, nlyr)
resolution  : 0.25, 0.25  (x, y)
extent  : 49.725, 49.975, 33.965, 34.215  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat Coordinate System imported from GRIB file
source  : Met.grib
name: SFC (Ground or water surface); Total precipitation [m]
unit:  m
time: 2019-12-31 23:00:00 UTC


# Extracting data for each parameter
> param_names <- c("param1", "param2", "param3", "param4", "param5",
"param6")
> extracted_data <- extract(raster_data, param_names, df = TRUE)
 #Error in (function (classes, fdef, mtable)  :
 #unable to find an inherited method for function ‘extract’ for signature
‘"SpatRaster", "character"’

> param_values <- lapply(raster_data, param_names)
#Error: std::bad_alloc

How can I do this?
I have no idea how to extract some of the .grib file to attach it.
Sincerely



On Tue, Jun 25, 2024 at 8:38 PM javad bayat  wrote:

> Dear Bert and Sara;
> I have searched on the internet and found some way to do this like python.
> But python is so complicated to me as it needs many steps to be done for
> reading and converting it.
> I will try terra package to convert it.
>
>
> On Tue, 25 Jun 2024, 15:15 javad bayat,  wrote:
>
>> Richard,
>> Many thanks for your email.
>> I had attached the grib file to the original email to R help team but it
>> seems you did not receive it.
>> Unfortunately, I do not know how to reduce the volume or extract some of
>> the grib file data to send it for you. The file has the volume of 6
>> Megabyte.
>> I can send it by email.
>> The file has 6 met parameters and Date (day/month/year hour:minute).
>> I want the exported file as excel contains 7 columns (Date + 6 met
>> parameters).
>>
>>
>> On Tue, 25 Jun 2024, 15:54 Richard O'Keefe,  wrote:
>>
>>> Your message referred to an attached file but there was no attachment,
>>> I have no account at that service, so could not download a sample for
>>> myself.  Does the licence for the data even allow you to send some of
>>> it in a message?  Which parameters are you extracting?  When you say
>>> "it didn't work", what actually happened?  Which step went wrong and how?
>>>
>>>
>>> On Tue, 25 Jun 2024 at 20:33, javad bayat  wrote:
>>> >
>>> > Dear all;
>>> > I have downloaded meteorology data from "
>>> >
>>> https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=form
>>> "
>>> > as .grib format. It has hourly data of a complete year (every hour of
>>> every
>>> > day of 12 months) and has 6 meteorology parameters. The file has been
>>> > attached.
>>> > I am trying to convert it to an excel file that puts every parameter
>>> in a
>>> > separated column. For instance, the firs

Re: [R] Converting .grib to excel file

2024-06-28 Thread javad bayat
Dear Richard,
I could not extract the data at all.
But what I found is that, the data stored in the grib file converted into
raster layer, and as I had 6 met parameters for a complete year (6 × 365 ×
24) the raster layer has 52,560 layer. The first layer belongs to the first
parameter for the first hour and second layer to the second parameters for
the first hour. .
And again the seven layer belongs to the first parameter for the second
hour and the layer number 8 belongs to the second param. for the second
hour  and this cycle is repeated until the layer number 52,560.
I think writing a function to extract these data can be helpful. For
example writing a function to extract the data number 1 and 7 and 13 and
... store in the first column and data number 2,8,14,  stor in the
second column and doing this for other parameters to complete the table and
eventually create a column for Date.
Can you help me to write a function.
Sincerely

On Wed, 26 Jun 2024, 12:44 Richard O'Keefe,  wrote:

> Whoops, sorry, you *did* answer "what went wrong".
> > param_names <- c("param1", "param2", "param3", "param4", "param5",
> "param6")
> > extracted_data <- extract(raster_data, param_names, df = TRUE)
>  #Error in (function (classes, fdef, mtable)  :
>  #unable to find an inherited method for function ‘extract’ for
> signature ‘"SpatRaster", "character"’
>
> OK.  The problem is that the extract() function didn't know what to do.
> What does the documentation for 'extract' say?
> The error message seems to say that it is not defined for first argument
> being
> a SpatRaster and second argument being of type character.
>
> (By the way, I'm having trouble updating the terra package in Ubuntu 22.04.
> That's why I'm not trying any of this out.)
>
> Here's what ?extract starts with:
>
> Extract values from a SpatRaster for a set of locations. The
>  locations can be a SpatVector (points, lines, polygons), a
>  data.frame or matrix with (x, y) or (longitude, latitude - in that
>  order!) coordinates, or a vector with cell numbers.
>
> It does NOT say that the set of locations can be a vector of strings.
>
>
> On Wed, 26 Jun 2024 at 20:05, Richard O'Keefe  wrote:
> >
> > I'm now inclined to go with 'search for "convert GRIB to CSV".
> > https://confluence.ecmwf.int/display/CKB/How+to+convert+GRIB+to+CSV
> > is the first line.  I know that's not an R solution, but using software
> > specifically developed for encoding, decoding, extracting, &c GRIB file
> by the
> > European Centre for Medium-Range Weather Forecasts and actively
> > maintained, with an example page showing how to do it, sounds like a
> > good approach.
> >
> > One of the major things about R is that from the very beginnings of S
> > it was intended to be used with other tools.  We have R communicating
> > with Python and Tcl and dear knows what.  Getting a specialised tool
> > to do its thing is very much part of the R "way".
> > Or there's gribr https://rdrr.io/github/nawendt/gribr/man/gribr.html
> > which wraps ecCodes in R.
> >
> > I still don't understand what "doesn't work" means.  Which step goes
> > wrong and how does it misbehave?
> >
> >
> > On Wed, 26 Jun 2024 at 06:02, javad bayat  wrote:
> > >
> > > Richard,
> > > Many thanks for your email.
> > > I had attached the grib file to the original email to R help team but
> it seems you did not receive it.
> > > Unfortunately, I do not know how to reduce the volume or extract some
> of the grib file data to send it for you. The file has the volume of 6
> Megabyte.
> > > I can send it by email.
> > > The file has 6 met parameters and Date (day/month/year hour:minute).
> > > I want the exported file as excel contains 7 columns (Date + 6 met
> parameters).
> > >
> > >
> > > On Tue, 25 Jun 2024, 15:54 Richard O'Keefe,  wrote:
> > >>
> > >> Your message referred to an attached file but there was no attachment,
> > >> I have no account at that service, so could not download a sample for
> > >> myself.  Does the licence for the data even allow you to send some of
> > >> it in a message?  Which parameters are you extracting?  When you say
> > >> "it didn't work", what actually happened?  Which step went wrong and
> how?
> > >>
> > >>
> > >> On Tue, 25 Jun 2024 at 20:33, javad bayat 
> wrote:
> > >> >

[R] surface plot

2013-07-28 Thread javad bayat
Dear R users;
I have a question about surface plot that show me spatial variability of
parameter. I have a data frame with 6 variables and X and Y for coordinate
system.

X   Y  pH
.....  ...

so I want to create a surface plot for my data.
please help me.
many thanks.

[[alternative HTML version deleted]]

__
R-help@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.


[R] R function

2013-07-28 Thread javad bayat
Dear R users;
I am MSc student and I want to write my own function, but it cant be
completed. please help me for solve it. here is my code:

pah1$P = (pah1$Fluoranthene/pah1$Pyrene)
T = function(x){
for (i in 1:length(pah1$P))
if (i >= 1)
print("Combustion")
if (i < 1)
print("Petroleum")
}
T(pah1$P[c(1:83),])

I wish that R gives me a column that if value greater or equal to one give
"Combustion"  and if value is less than one give "Petroleum".
but my function dose not work.
thank you so much for your help.

[[alternative HTML version deleted]]

__
R-help@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.


[R] saving to docx

2012-10-19 Thread javad bayat
hi all,
how can i saving R output to docx or Jpeg format?

[[alternative HTML version deleted]]

__
R-help@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.


[R] Logistic Regression

2014-06-14 Thread javad bayat
Dear all, I have to use "Zelig" package for doing logistic regression.
How can I use Zelig package for logistic regression?

I did this code by glm function:

glm1 = glm(kod~Curv+Elev+Out.c+Slope+Aspect,data=data,
   family=binomial)
summary(glm1)

But the results were not appropriate for my data.

Many thanks for your helps.







-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Shahid Beheshti (National) University (SBU)
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

__
R-help@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.


[R] Biplot interpretation

2014-06-24 Thread javad bayat
Dear all;
I did biplot in R. How can I interpret them in order that i can create two
or more groups in each biplot. I wanna determine the variables that have
the same origin.
please help me.
many thanks.









-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Shahid Beheshti (National) University (SBU)
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

__
R-help@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.


[R] spplot help

2014-07-20 Thread javad bayat
Dear all
I am using spplot command to plot my raster. I make it but there is two
problems with me.
1- I want to have no border or greater border around the raster
2- I want to insert a legend with a header aside from its legend.

please help me.

thanks in advance.

-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Shahid Beheshti (National) University (SBU)
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

__
R-help@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.


[R] help

2014-01-05 Thread javad bayat
Dear all;
I am Msc student in Iran and I used R software for statistical analysis in
my master thesis.
I have 2 request:
First:
I am interested in writing a package in R and I do not know how can I do
it.
Please lead me or forward to me an clip or pdf or any thing that helps me
to learn some thing about that.

Second:
I have a data (which is attached) for a river and I want to predict the
next month for each variables based on Neural nrtwork. But i cant write a
formula for predicting these var.
please help me to do it. I need this for my project.
I am looking forward to hear from you due to the case.

many thanks.
all bests.

-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Shahid Beheshti (National) University (SBU)
Alternative Mail: bayat...@yahoo.com
__
R-help@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.


Re: [R] help

2014-01-05 Thread javad bayat
Dear all;
many thanks for your answers.
Hear is my data (not all row: the station was 8 station at 20 month) which
I forward it as image. I hope some one can help me to do Neural network for
prediction of next month.
many thanks.
all bests.






-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Shahid Beheshti (National) University (SBU)
Alternative Mail: bayat...@yahoo.com
<>__
R-help@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.


Re: [R] help

2014-01-06 Thread javad bayat
Dear Saha thank you to reminding me. Here is the text file.


On Mon, Jan 6, 2014 at 10:33 AM, Koushik Saha wrote:

> please don't send images . paste your data in a text file with .text
> extension and attach it
>
>
> On Mon, Jan 6, 2014 at 12:06 PM, javad bayat  wrote:
>
>> Dear all;
>> many thanks for your answers.
>> Hear is my data (not all row: the station was 8 station at 20 month) which
>> I forward it as image. I hope some one can help me to do Neural network
>> for
>> prediction of next month.
>> many thanks.
>> all bests.
>>
>>
>>
>>
>>
>>
>> --
>> Best Regards
>> Javad Bayat
>> M.Sc. Environment Engineering
>> Shahid Beheshti (National) University (SBU)
>> Alternative Mail: bayat...@yahoo.com
>>
>> __
>> R-help@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.
>>
>>
>


-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Shahid Beheshti (National) University (SBU)
Alternative Mail: bayat...@yahoo.com
station month   pH  EC  N   %OM
1   1   8.360.8155.50   1.03
1   2   8.102.53208.75  1.01
1   3   8.420.9034.50   1.40
1   4   8.290.8978.42   1.11
1   5   8.311.28161.25  0.62
1   6   8.400.6549.92   1.23
1   7   7.971.1370.58   1.27
1   8   8.301.3281.67   1.01
1   9   8.411.33128.67  1.72
1   10  8.341.4381.08   1.19
1   11  8.461.0568.33   1.42
1   12  8.480.9564.17   1.05
1   13  8.245.32433.33  1.58
1   14  8.550.7724.67   0.98
1   15  8.502.77150.92  1.66
1   16  8.054.52411.67  1.07
1   17  8.232.03321.67  1.09
1   18  8.064.67382.50  1.48
1   19  8.560.5532.42   1.09
1   20  8.402.66199.00  2.11
2   1   8.340.9797.08   0.88
2   2   8.171.1124.00   0.66
2   3   8.511.2371.33   0.72
2   4   8.451.41107.33  1.21
2   5   8.431.57103.33  0.98
2   6   8.751.2367.00   0.94
2   7   8.581.0276.33   0.82
2   8   8.290.7635.50   0.92
2   9   8.001.08425.00  2.24
2   10  8.341.0265.50   1.79
2   11  8.600.8336.67   1.15
2   12  8.600.7740.00   1.27
2   13  8.400.8473.83   1.33
2   14  8.600.6145.00   0.98
2   15  8.680.8236.67   0.66
2   16  8.381.74117.75  1.48
2   17  8.651.2976.83   1.62
2   18  8.561.95111.08  1.77
2   19  8.521.6368.33   1.95
2   20  8.431.2284.25   1.85
3   1   7.953.54384.17  0.98
3   2   8.102.57364.17  1.50
3   3   7.8710.86   231.67  0.88
3   4   8.671.7137.00   0.78
3   5   8.540.9965.92   1.17
3   6   8.642.7448.17   1.13
3   7   8.185.14161.75  0.47
3   8   8.067.33471.67  1.01
3   9   8.261.7931.33   0.98
3   10  8.353.6036.83   1.17
3   11  8.353.5131.67   1.23
3   12  8.624.4339.50   1.17
3   13  8.287.27375.00  0.10
3   14  8.155.48241.67  0.35
3   15  8.043.4985.67   0.96
3   16  8.314.0929.17   0.66
3   17  8.642.0658.00   0.62
3   18  8.201.9428.33   0.74
3   19  8.571.78186.42  1.35
3   20  8.001.4155.42   1.15
4   1   8.280.6055.92   1.38
4   2   8.220.8963.33   1.79
4   3   7.843.09182.25  1.31
4   4   7.902.7379.00   1.01
4   5   8.521.0068.33   1.60
4   6   7.974.0428.83   0.90
4   7   8.414.6852.00   1.15
4   8   8.651.2713.08   0.60
4   9   8.608.4355.83   0.78
4   10  8.694.53219.92  0.74
4   11  8.383.4624.33   0.45
4   12  8.806.08601.67  0.23
4   13  8.012.97111.75  0.39
4   14  7.6412.78   590.00  0.86
4   15  7.823.96138.67  0.98
4   16  7.981.56477.50  0.90
4   17  8.250.8641.25   1.01
4   18  7.655.15117.50  0.94
4   19  8.192.6695.67   0.74
4   20  8.402.4673

Re: [R] help

2014-01-06 Thread javad bayat
Dear Petr;
I saw the nnet and neuralnet packag, and I cant find some thing relating
with my data based on neural network.


On Mon, Jan 6, 2014 at 10:55 AM, PIKAL Petr  wrote:

> Hi
>
> Why you did not use dput for sending data? It is far better than picture,
> which can not be used without retyping.
>
> Redarding neural network, did you try e.g. nnet or neuralnet package.
>
> Petr
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > project.org] On Behalf Of javad bayat
> > Sent: Monday, January 06, 2014 7:37 AM
> > To: R-help@r-project.org
> > Subject: Re: [R] help
> >
> > Dear all;
> > many thanks for your answers.
> > Hear is my data (not all row: the station was 8 station at 20 month)
> > which I forward it as image. I hope some one can help me to do Neural
> > network for prediction of next month.
> > many thanks.
> > all bests.
> >
> >
> >
> >
> >
> >
> > --
> > Best Regards
> > Javad Bayat
> > M.Sc. Environment Engineering
> > Shahid Beheshti (National) University (SBU) Alternative Mail:
> > bayat...@yahoo.com
>



-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Shahid Beheshti (National) University (SBU)
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] help

2014-01-07 Thread javad bayat
I apologies for asking this question;
I run the codes but why all the prediction for pH in 21-25 month are so
close?
 station month  pH
  1   21  8.275635958
  2   21  8.275635962
  3   21  8.275635963
  4   21  8.275635963
  5   21  8.275635963
  6   21  8.275635963



On Tue, Jan 7, 2014 at 2:12 PM, javad bayat  wrote:

> Dear Pikal Petr;
> thanks for code.
> It was usefull.
>
>
>
> On Tue, Jan 7, 2014 at 11:30 AM, PIKAL Petr wrote:
>
>>  Hi
>>
>>
>>
>> and what is wrong with e.g.
>>
>>
>>
>> fit  <- neuralnet(pH~station+month, data=yourdata)
>>
>>
>>
>> As I said I am not an expert in neural nets  but here is some explanation
>> how it works
>>
>> http://gekkoquant.com/2012/05/26/neural-networks-with-r-simple-example/
>>
>>
>>
>> based on that after fitting you could do
>>
>>
>>
>> compute(fit, testdata)
>>
>>
>>
>> where testdata shall be station and month.
>>
>>
>>
>> However for time series it can be more appropriate something like ARIMA
>> modelling.
>>
>>
>>
>> Petr
>>
>>
>>
>> *From:* javad bayat [mailto:j.bayat...@gmail.com]
>> *Sent:* Monday, January 06, 2014 5:58 PM
>> *To:* PIKAL Petr
>> *Subject:* Re: [R] help
>>
>>
>>
>> Dear Petr;
>>
>> I want to write function that: for example for pH:
>>
>> according these 20 months predict the variability of pH for next month
>> and stations.
>>
>> all best.
>>
>>
>>
>> On Mon, Jan 6, 2014 at 7:23 PM, PIKAL Petr 
>> wrote:
>>
>> Hi
>> can you be more specific? In what aspect those packages does not comply
>> with your data? What did you do for testing it?
>>
>> I am not an expert in neural networks but I do not see anything which
>> prevents using your data in nnet.
>>
>>
>> Petr
>>
>>
>> > -Original Message-
>> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> > project.org] On Behalf Of javad bayat
>>
>> > Sent: Monday, January 06, 2014 3:16 PM
>> > To: R-help@r-project.org
>> > Subject: Re: [R] help
>> >
>>
>> > Dear Petr;
>>
>> > I saw the nnet and neuralnet packag, and I cant find some thing
>> > relating with my data based on neural network.
>> >
>> >
>> > On Mon, Jan 6, 2014 at 10:55 AM, PIKAL Petr 
>> > wrote:
>> >
>> > > Hi
>> > >
>> > > Why you did not use dput for sending data? It is far better than
>> > > picture, which can not be used without retyping.
>> > >
>> > > Redarding neural network, did you try e.g. nnet or neuralnet package.
>> > >
>> > > Petr
>> > >
>> > > > -Original Message-
>> > > > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> > > > project.org] On Behalf Of javad bayat
>> > > > Sent: Monday, January 06, 2014 7:37 AM
>> > > > To: R-help@r-project.org
>> > > > Subject: Re: [R] help
>> > > >
>> > > > Dear all;
>> > > > many thanks for your answers.
>> > > > Hear is my data (not all row: the station was 8 station at 20
>> > month)
>> > > > which I forward it as image. I hope some one can help me to do
>> > > > Neural network for prediction of next month.
>> > > > many thanks.
>> > > > all bests.
>> > > >
>> > > >
>> > > >
>> > > >
>> > > >
>> > > >
>> > > > --
>> > > > Best Regards
>> > > > Javad Bayat
>> > > > M.Sc. Environment Engineering
>> > > > Shahid Beheshti (National) University (SBU) Alternative Mail:
>> > > > bayat...@yahoo.com
>> > >
>> >
>> >
>> >
>> > --
>> > Best Regards
>> > Javad Bayat
>> > M.Sc. Environment Engineering
>> > Shahid Beheshti (National) University (SBU) Alternative Mail:
>> > bayat...@yahoo.com
>> >
>>
>> >   [[alternative HTML version deleted]]
>>
>> >
>> > __
>> > R-help@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.
>>
>>
>>
>>
>>
>> --
>>
>> Best Regards
>> Javad Bayat
>> M.Sc. Environment Engineering
>> Shahid Beheshti (National) University (SBU)
>> Alternative Mail: bayat...@yahoo.com
>>
>
>
>
> --
> Best Regards
> Javad Bayat
> M.Sc. Environment Engineering
> Shahid Beheshti (National) University (SBU)
> Alternative Mail: bayat...@yahoo.com
>



-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Shahid Beheshti (National) University (SBU)
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

__
R-help@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.


[R] Extracting wind direction and wind speed from wind rose plot

2024-10-30 Thread javad bayat
Dear all;
I am searching for a way to extract wind direction and speed from a wind
rose plot. I have a graph and I want to make a dataframe of 5 years with
hourly intervals.

> start_date <- as.POSIXct("2019-01-01 00:00:00")
> end_date <- as.POSIXct("2023-12-31 23:00:00")
> time_sequence <- seq(from = start_date, to = end_date, by = "hour")

> df <- data.frame(
  year = as.integer(format(time_sequence, "%Y")),
  month = as.integer(format(time_sequence, "%m")),
  day = as.integer(format(time_sequence, "%d")),
  hour = as.integer(format(time_sequence, "%H"))
)

> head(df)
  year month day hour
1 2019 1   10
2 2019 1   11
3 2019 1   12
4 2019 1   13
5 2019 1   14
6 2019 1   15


And I want to add 2 more cols to this dataframe as Wind_Dir and Wind_Speed
that the data extracted from the plot by analyzing it.
Is there any library to do this? or any function to write for this purpose?
I would be more than happy if you please help me to do this.
Sincerely







-- 
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 https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with converting grib file to excel

2024-09-25 Thread javad bayat
Dear all;
Many thanks for your responses. Actually it is not completely a GIS file,
it is a data file which stores meteorological data of a specific region.
But the site allows downloading with grib format and as I searched to read
this type of file in R, I found the Raster Package.
In python it is possible to do this using cdsapi and xarray library, but I
am not familiar with python.
Sincerely

On Thu, Sep 26, 2024 at 2:33 AM Roy Mendelssohn - NOAA Federal via R-help <
r-help@r-project.org> wrote:

> At least for me the dataset file did not come through.  I will look at it
> if it can be made available.  It does look like the finial step of reading
> the data into raster failed,  so then did the rest of th commands.
>
> -Roy
>
>
> > On Sep 25, 2024, at 3:24 PM, CALUM POLWART  wrote:
> >
> > Noticeable lack of silence in the group on this one.
> >
> > I've not got time to test currently. But my experience of geo location
> > files - they often had more than 2 dimensional data. In other words you
> > might have a boundary of a region as an object with long and lat for
> maybe
> > 100 data points making up the region. So 200 pieces of data. All held as
> a
> > list or something similar in a single "cell" as excel would refer to it.
> >
> > My gut feeling is that's likely to make export to excel difficult without
> > data carpentry first?
> >
> > On Tue, 24 Sep 2024, 21:26 Bert Gunter,  wrote:
> >
> >> You might try posting on r-sig-geo if you don't get a satisfactory
> >> response here. I assume there's a lot of expertise there on handling
> >> raster-type data.
> >>
> >> Cheers,
> >> Bert
> >>
> >> On Mon, Sep 23, 2024 at 11:31 PM javad bayat 
> wrote:
> >>>
> >>> Dear R users;
> >>> I have downloaded a grib file format (Met.grib) and I want to export
> its
> >>> data to excel file. Also I want to do some mathematic on some columns.
> >> But
> >>> I got error. I would be more than happy if anyone can help me to do
> >> this. I
> >>> have provided the codes and the Met.grib file in this email.
> >>> Sincerely yours
> >>>
> >>> # Load the necessary libraries
> >>>> library(raster)  # For reading GRIB files
> >>>> library(dplyr)   # For data manipulation
> >>>> library(lubridate)   # For date manipulation
> >>>> library(openxlsx)# For writing Excel files
> >>>
> >>> # Specify the file paths
> >>>> grib_file_path <- "C:/Users/Omrab_Lab/Downloads/Met.grib"
> >>>> excel_file_path <- "C:/Users/Omrab_Lab/Downloads/Met_updated.xlsx"
> >>>
> >>> # Open the GRIB file
> >>>> raster_data <- stack(grib_file_path)
> >>>
> >>> # Check the names of the layers to identify which ones to extract
> >>>> layer_names <- names(raster_data)
> >>>> print(layer_names)  # Prints
> >>>
> >>>
> >>>> # Extract layers based on layer names - adjust as necessary
> >>>> t2m <- raster_data[[grep("t2m", layer_names)]]
> >>>> d2m <- raster_data[[grep("d2m", layer_names)]]
> >>>> tcc <- raster_data[[grep("tcc", layer_names)]]
> >>>> valid_time <- raster_data[[grep("valid_time", layer_names)]]
> >>>> t2m
> >>> class  : RasterStack
> >>> nlayers: 0
> >>>
> >>>> # Check if the raster layers are loaded correctly
> >>>> if (is.null(t2m) || is.null(d2m) || is.null(tcc) ||
> >> is.null(valid_time))
> >>> {
> >>> + stop("One or more raster layers could not be loaded. Please check
> >> the
> >>> layer names.")
> >>> + }
> >>>
> >>>> # Convert raster values to vectors
> >>>> t2m_values <- values(t2m)
> >>> Error in dimnames(x) <- dn :
> >>>  length of 'dimnames' [2] not equal to array extent
> >>>> d2m_values <- values(d2m)
> >>> Error in dimnames(x) <- dn :
> >>>  length of 'dimnames' [2] not equal to array extent
> >>>> tcc_values <- values(tcc)
> >>> Error in dimnames(x) <- dn :
> >>>  length of 'dimnames' [2] not equal to array extent
> >>>> valid_time_values <- values(valid_time)
> >>> Error in dimnames(x) <- dn 

Re: [R] Problem with converting grib file to excel

2024-09-26 Thread javad bayat
Dear Roy,
Sorry for my mistake, I thought I have uploaded the grib file.
I really apologise for that. I will send it   on Saturday.
Thank you very much.

On Thu, 26 Sept 2024, 17:40 Roy Mendelssohn - NOAA Federal, <
roy.mendelss...@noaa.gov> wrote:

> Hi Javad:
>
> I know a lot about reading GRIB files,  I work with them all the time.
> But if you don’t make the file available,  or point me to where I can
> download it,  there is not much I can do.
>
> Thanks,
>
> -Roy
>
> On Sep 25, 2024, at 9:41 PM, javad bayat  wrote:
>
> Dear all;
> Many thanks for your responses. Actually it is not completely a GIS file,
> it is a data file which stores meteorological data of a specific region.
> But the site allows downloading with grib format and as I searched to read
> this type of file in R, I found the Raster Package.
> In python it is possible to do this using cdsapi and xarray library, but I
> am not familiar with python.
> Sincerely
>
> On Thu, Sep 26, 2024 at 2:33 AM Roy Mendelssohn - NOAA Federal via R-help <
> r-help@r-project.org> wrote:
>
>> At least for me the dataset file did not come through.  I will look at it
>> if it can be made available.  It does look like the finial step of reading
>> the data into raster failed,  so then did the rest of th commands.
>>
>> -Roy
>>
>>
>> > On Sep 25, 2024, at 3:24 PM, CALUM POLWART  wrote:
>> >
>> > Noticeable lack of silence in the group on this one.
>> >
>> > I've not got time to test currently. But my experience of geo location
>> > files - they often had more than 2 dimensional data. In other words you
>> > might have a boundary of a region as an object with long and lat for
>> maybe
>> > 100 data points making up the region. So 200 pieces of data. All held
>> as a
>> > list or something similar in a single "cell" as excel would refer to it.
>> >
>> > My gut feeling is that's likely to make export to excel difficult
>> without
>> > data carpentry first?
>> >
>> > On Tue, 24 Sep 2024, 21:26 Bert Gunter,  wrote:
>> >
>> >> You might try posting on r-sig-geo if you don't get a satisfactory
>> >> response here. I assume there's a lot of expertise there on handling
>> >> raster-type data.
>> >>
>> >> Cheers,
>> >> Bert
>> >>
>> >> On Mon, Sep 23, 2024 at 11:31 PM javad bayat 
>> wrote:
>> >>>
>> >>> Dear R users;
>> >>> I have downloaded a grib file format (Met.grib) and I want to export
>> its
>> >>> data to excel file. Also I want to do some mathematic on some columns.
>> >> But
>> >>> I got error. I would be more than happy if anyone can help me to do
>> >> this. I
>> >>> have provided the codes and the Met.grib file in this email.
>> >>> Sincerely yours
>> >>>
>> >>> # Load the necessary libraries
>> >>>> library(raster)  # For reading GRIB files
>> >>>> library(dplyr)   # For data manipulation
>> >>>> library(lubridate)   # For date manipulation
>> >>>> library(openxlsx)# For writing Excel files
>> >>>
>> >>> # Specify the file paths
>> >>>> grib_file_path <- "C:/Users/Omrab_Lab/Downloads/Met.grib"
>> >>>> excel_file_path <- "C:/Users/Omrab_Lab/Downloads/Met_updated.xlsx"
>> >>>
>> >>> # Open the GRIB file
>> >>>> raster_data <- stack(grib_file_path)
>> >>>
>> >>> # Check the names of the layers to identify which ones to extract
>> >>>> layer_names <- names(raster_data)
>> >>>> print(layer_names)  # Prints
>> >>>
>> >>>
>> >>>> # Extract layers based on layer names - adjust as necessary
>> >>>> t2m <- raster_data[[grep("t2m", layer_names)]]
>> >>>> d2m <- raster_data[[grep("d2m", layer_names)]]
>> >>>> tcc <- raster_data[[grep("tcc", layer_names)]]
>> >>>> valid_time <- raster_data[[grep("valid_time", layer_names)]]
>> >>>> t2m
>> >>> class  : RasterStack
>> >>> nlayers: 0
>> >>>
>> >>>> # Check if the raster layers are loaded correctly
>> >>>> if (is.null(t2m) || is.null(d2m) || is.null(tcc) ||
>> >> is.null

[R] Problem with converting grib file to excel

2024-09-23 Thread javad bayat
Dear R users;
I have downloaded a grib file format (Met.grib) and I want to export its
data to excel file. Also I want to do some mathematic on some columns. But
I got error. I would be more than happy if anyone can help me to do this. I
have provided the codes and the Met.grib file in this email.
Sincerely yours

# Load the necessary libraries
>  library(raster)  # For reading GRIB files
>  library(dplyr)   # For data manipulation
>  library(lubridate)   # For date manipulation
>  library(openxlsx)# For writing Excel files

# Specify the file paths
>  grib_file_path <- "C:/Users/Omrab_Lab/Downloads/Met.grib"
>  excel_file_path <- "C:/Users/Omrab_Lab/Downloads/Met_updated.xlsx"

# Open the GRIB file
>  raster_data <- stack(grib_file_path)

# Check the names of the layers to identify which ones to extract
>  layer_names <- names(raster_data)
> print(layer_names)  # Prints


> # Extract layers based on layer names - adjust as necessary
> t2m <- raster_data[[grep("t2m", layer_names)]]
> d2m <- raster_data[[grep("d2m", layer_names)]]
> tcc <- raster_data[[grep("tcc", layer_names)]]
> valid_time <- raster_data[[grep("valid_time", layer_names)]]
> t2m
class  : RasterStack
nlayers: 0

> # Check if the raster layers are loaded correctly
> if (is.null(t2m) || is.null(d2m) || is.null(tcc) || is.null(valid_time))
{
+ stop("One or more raster layers could not be loaded. Please check the
layer names.")
+ }

> # Convert raster values to vectors
> t2m_values <- values(t2m)
Error in dimnames(x) <- dn :
  length of 'dimnames' [2] not equal to array extent
> d2m_values <- values(d2m)
Error in dimnames(x) <- dn :
  length of 'dimnames' [2] not equal to array extent
> tcc_values <- values(tcc)
Error in dimnames(x) <- dn :
  length of 'dimnames' [2] not equal to array extent
> valid_time_values <- values(valid_time)
Error in dimnames(x) <- dn :
  length of 'dimnames' [2] not equal to array extent

# Check for NA values and dimensions
if (any(is.na(t2m_values)) || any(is.na(d2m_values)) || any(is.na(tcc_values))
|| any(is.na(valid_time_values))) {
  warning("One or more layers contain NA values. These will be removed.")
}

# Create the data frame, ensuring no NA values are included
df <- data.frame(
  t2m = t2m_values,
  d2m = d2m_values,
  tcc = tcc_values,
  valid_time = valid_time_values,
  stringsAsFactors = FALSE
)

# Remove rows with NA values
df <- na.omit(df)

# Convert temperatures from Kelvin to Celsius
df$t2m <- df$t2m - 273.15
df$d2m <- df$d2m - 273.15

# Calculate relative humidity
calculate_relative_humidity <- function(t2m, d2m) {
  es <- 6.112 * exp((17.67 * t2m) / (t2m + 243.5))
  e <- 6.112 * exp((17.67 * d2m) / (d2m + 243.5))
  rh <- (e / es) * 100
  return(rh)
}
df$RH <- calculate_relative_humidity(df$t2m, df$d2m)

# Convert valid_time from numeric to POSIXct assuming it's in seconds since
the epoch
df$valid_time <- as.POSIXct(df$valid_time, origin = "1970-01-01")

# Extract year, month, day, and hour from valid_time
df$Year <- year(df$valid_time)
df$Month <- month(df$valid_time)
df$Day <- day(df$valid_time)
df$Hour <- hour(df$valid_time)

# Select only the desired columns
df_selected <- df %>% select(Year, Month, Day, Hour, tcc, t2m, RH)

# Save the updated DataFrame to an Excel file
write.xlsx(df_selected, excel_file_path, row.names = FALSE)






-- 
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 https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Convert poly line to polygon in R

2017-11-12 Thread Javad Bayat via R-help
I have a shape file as poly line and I want to convert it to polygon.Is it 
possible to do that in R?lake 
<-readShapeLines("./lake_main_utm.shp")proj4string(lake) <- CRS("+proj=utm 
+zone=39 +datum=WGS84")

Sincerely.

[[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] how to label station names on point

2017-11-12 Thread Javad Bayat via R-help
I have a shapefile point and I plot it over my polygon. Is it possible to label 
station names over points?Sincerely.
S_Point = readOGR(".","point")plot(S_Point,add=TRUE,col="black",pch=20,cex=2)




[[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] Neural Network

2015-01-20 Thread javad bayat via R-help
Dear all;
I am the new user of R. I want to simulation or prediction the Eutrophication 
of a lake. I have weekly data(almost for two years) for Total phosphorus, Total 
N, pH, Chlorophyll a, Alkalinity, Silica.
Can I predict the Eutrophication by Neural Network in R?
How can I simulation the Eutrophication by these parameter? 
please help me to write the codes.
many thanks.

__
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] Neural Network

2015-01-23 Thread javad bayat via R-help
Dear Charles;
I think my variables are dependent. For e.g. the concentration of  Phosphorus, 
Nitrogen, Silica and etc. have effect on the present of Chlorophyll a and the 
concentration of Chlorophyll a can make the Eutrophication in lake along with 
other algeas. 
So I think they are dependent variables.
Regards. 




On Thu, 1/22/15, Charles Determan Jr  wrote:

 Subject: Re: [R] Neural Network

roject.org>
 Date: Thursday, January 22, 2015, 4:41 PM

 Javad,
 First,
 please make sure to hit 'reply all' so that these
 messages go to the R help list so others (many far more
 skilled than I) may possibly chime in.
 The problem here is that you appear
 to have no dependent variable (i.e. no eutrophication
 variable).  Without it, there is no way to a typical
 'supervised' analysis.  Given that this is likely a
 regression type problem (I assume eutrophication would be
 continous) I'm not quite sure 'supervised' is
 the correct description but it furthers my point that you
 need a dependent variable for any neuralnet algorithm I am
 aware of.  As such, if you don't have a dependent
 variable then you will need to look at unsupervised methods
 such as PCA.  Other users may have other
 suggestions.
 Regards,Charles
 On Wed, Jan 21, 2015 at

 wrote:
 Dear
 Charles;

 Many thanks for your attention. what I want to know is: How
 can I predict the Eutrophication by these parameters in the
 future?

 These variables are the most important variables that
 control the Eutro. in lakes.

 Let me break it to two parts.

 1) How can I predict these variables by NN?

 2) Is it possible to predict the Eutro. by these
 variables?





 Many thanks for your help.

  Regards,















 

 On Wed, 1/21/15, Charles Determan Jr 
 wrote:



  Subject: Re: [R] Neural Network



  Cc: "r-help@r-project.org"
 

  Date: Wednesday, January 21, 2015, 9:10 PM



  Javad,

  You

  question is a little too broad to be answered

  definitively.  Also, this is not a code writing
 service. 

  You should make a meaningful attempt and we are here to
 help

  when you get stuck.

  1.

  If you want to know if you can do neural nets, the answer
 is

  yes.  The three packages most commonly used (that I
 know

  of) are 'neuralnet', 'nnet' and

  'RSNNS'.  You should look in to these package

  documentation for how to use them.  There are also
 many

  examples online if you simply google them.

  2. You question is unclear, are you

  wanting to predict all the variables (e.g. phosphorus,
 Total

  N, etc.) or do you have some metric for
 eutrophication? 

  What exactly is the model supposed to predict?

  3. If you want to know if a

  neuralnet is appropriate, that is more of a statistical

  question.  It depends more on the question you want to

  answer.  Given your temporal data, you may want to look
 in

  to mixed effects models (e.g nlme, lme4) as another

  potential approach.

  Regards,

  On Tue, Jan 20, 2015 at

  11:35 PM, javad bayat via R-help 

  wrote:

  Dear

  all;



  I am the new user of R. I want to simulation or
 prediction

  the Eutrophication of a lake. I have weekly data(almost
 for

  two years) for Total phosphorus, Total N, pH, Chlorophyll
 a,

  Alkalinity, Silica.



  Can I predict the Eutrophication by Neural Network in
 R?



  How can I simulation the Eutrophication by these

  parameter?



  please help me to write the codes.



  many thanks.







  __



  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.









  --

  Dr. Charles Determan, PhD

  Integrated Biosciences








 -- 
 Dr. Charles Determan, PhD
 Integrated Biosciences

__
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] Neural Network

2015-01-23 Thread javad bayat via R-help
Dear All;
Many thanks for your attention. what I want to know is: How can I predict the 
Eutrophication by these parameters in the future?
These variables are the most important variables that control the Eutro. in 
lakes.
Let me break it to two parts.
1) How can I predict these variables by NN?
2) Is it possible to predict the Eutro. by these variables?


Many thanks for your help.
Regards,

On Thu, 1/22/15, Charles Determan Jr  wrote:

 Subject: Re: [R] Neural Network

roject.org>
 Date: Thursday, January 22, 2015, 4:41 PM

 Javad,
 First,
 please make sure to hit 'reply all' so that these
 messages go to the R help list so others (many far more
 skilled than I) may possibly chime in.
 The problem here is that you appear
 to have no dependent variable (i.e. no eutrophication
 variable).  Without it, there is no way to a typical
 'supervised' analysis.  Given that this is likely a
 regression type problem (I assume eutrophication would be
 continous) I'm not quite sure 'supervised' is
 the correct description but it furthers my point that you
 need a dependent variable for any neuralnet algorithm I am
 aware of.  As such, if you don't have a dependent
 variable then you will need to look at unsupervised methods
 such as PCA.  Other users may have other
 suggestions.
 Regards,Charles
 On Wed, Jan 21, 2015 at

 wrote:
 Dear
 Charles;

 Many thanks for your attention. what I want to know is: How
 can I predict the Eutrophication by these parameters in the
 future?

 These variables are the most important variables that
 control the Eutro. in lakes.

 Let me break it to two parts.

 1) How can I predict these variables by NN?

 2) Is it possible to predict the Eutro. by these
 variables?





 Many thanks for your help.

  Regards,















 

 On Wed, 1/21/15, Charles Determan Jr 
 wrote:



  Subject: Re: [R] Neural Network



  Cc: "r-help@r-project.org"
 

  Date: Wednesday, January 21, 2015, 9:10 PM



  Javad,

  You

  question is a little too broad to be answered

  definitively.  Also, this is not a code writing
 service. 

  You should make a meaningful attempt and we are here to
 help

  when you get stuck.

  1.

  If you want to know if you can do neural nets, the answer
 is

  yes.  The three packages most commonly used (that I
 know

  of) are 'neuralnet', 'nnet' and

  'RSNNS'.  You should look in to these package

  documentation for how to use them.  There are also
 many

  examples online if you simply google them.

  2. You question is unclear, are you

  wanting to predict all the variables (e.g. phosphorus,
 Total

  N, etc.) or do you have some metric for
 eutrophication? 

  What exactly is the model supposed to predict?

  3. If you want to know if a

  neuralnet is appropriate, that is more of a statistical

  question.  It depends more on the question you want to

  answer.  Given your temporal data, you may want to look
 in

  to mixed effects models (e.g nlme, lme4) as another

  potential approach.

  Regards,

  On Tue, Jan 20, 2015 at

  11:35 PM, javad bayat via R-help 

  wrote:

  Dear

  all;



  I am the new user of R. I want to simulation or
 prediction

  the Eutrophication of a lake. I have weekly data(almost
 for

  two years) for Total phosphorus, Total N, pH, Chlorophyll
 a,

  Alkalinity, Silica.



  Can I predict the Eutrophication by Neural Network in
 R?



  How can I simulation the Eutrophication by these

  parameter?



  please help me to write the codes.



  many thanks.







  __



  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.









  --

  Dr. Charles Determan, PhD

  Integrated Biosciences








 -- 
 Dr. Charles Determan, PhD
 Integrated Biosciences

__
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.