[R] spgrass6 and aggregation (bis)

2007-06-06 Thread jessica . gervais

Dear all,

I have some additionale question concerning the spgrass6 package.

* When you set a region in GRASS, does the readGRASS6 function in R only
load data contained in the zoomed region or the whole map ?

* When you have a MASK map in grass, does the readGRASS6 function in R only
load data contained inside the MASK area ?


Could this be the problem ?

Thanks,

Jessica


3

Dear all,


I am exporting grass map into R thanks to the very useful spgrass6 package.

library(spgrass6)

# I have 3 map I am working with a MASK map of a specific area.

# 1) a landuse map
landuse<-readRAST6("landuse_mapname_in_grass")

# 2) a catchment map which divide the area in several catchements
catchment<-readRAST6("catchement_mapname_in_grass")

# 3) a precipitation map
precipitation<-readRAST6("precipitation_mapname_in_grass")


# then I would like to sum the precipitation spatialy over each catchment
and landuse. So, first I cbind all maps with cbind

MAP<-cbind(landuse,catchment,precipitation)

# then I use the aggregate function
SUM<-aggregate(MAP[3],by=list(MAP[1],MAP[2]),sum,na.rm=TRUE)
# here is the problem !!!
Error in as.vector(x, mode) : invalid argument 'mode'



I don't find any idea to solve this...

Does anyone has a suggestion ??

Thanks in advance


Jess

__
R-help@stat.math.ethz.ch 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] spgrass6 and aggregation

2007-06-06 Thread jessica . gervais

Dear all,


I am exporting grass map into R thanks to the very useful spgrass6 package.

library(spgrass6)

# I have 3 map I am working with a MASK map of a specific area.

# 1) a landuse map
landuse<-readRAST6("landuse_mapname_in_grass")

# 2) a catchment map which divide the area in several catchements
catchment<-readRAST6("catchement_mapname_in_grass")

# 3) a precipitation map
precipitation<-readRAST6("precipitation_mapname_in_grass")


# then I would like to sum the precipitation spatialy over each catchment
and landuse. So, first I cbind all maps with cbind

MAP<-cbind(Dear all,

__
R-help@stat.math.ethz.ch 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] time serie generation

2007-06-01 Thread jessica . gervais

Dear all,

I would like to generate a regular time serie, i.e. a list of dates and
time for each our of the period 2002-2004.

the time format should be
"2002-01-01 12:00:00" (year-month-day hour:min:sec)


so the list should contain all hours of the period 2002-2004
2002-01-01 00:00:00
2002-01-01 01:00:00
2002-01-01 02:00:00
...
2004-12-31 23:00:00
Does a function exist to create that kind of list ?

Thanks in advance,


Jessica

__
R-help@stat.math.ethz.ch 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] aggregation of a zoo object

2007-05-29 Thread jessica . gervais
Dear all,

I am trying to execute the following example:

time<-c("2000-10-03 14:00:00","2000-10-03 14:10:00","2000-10-03
14:20:00","2000-10-03 15:30:00","2000-10-03 16:40:00","2000-10-03
16:50:00","2000-10-03 17:00:00","2000-10-03 17:10:00","2000-10-03
17:20:00","2000-10-03 18:30:00","2000-10-04 14:00:00","2000-10-04
14:10:00","2000-10-04 14:20:00","2000-10-04 15:30:00","2000-10-04
16:40:00","2000-10-04 16:50:00","2000-10-04 17:00:00","2000-10-04
18:30:00","2000-10-04 18:30:00","2000-10-04 18:30:00")
# remark the last date is occuring 3 times

precipitation<-c(NA,0.1,0,0,NA,0,0.2,0.3,0.5,6,7,8,9,1,0,0,NA,0,1,0)

library(zoo)

z <- zoo(precipitation, as.POSIXct(time, tz = "GMT"))
Warning message:
some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique in: zoo(precipitation, as.POSIXct(time, tz =
"GMT"))

# then I want to do the sum per hour

z_sum_per_hour <- aggregate(na.omit(z), function(x) as.POSIXct(trunc(x,
"hour")),sum)
Warning message:
some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique in: zoo(rval[i], x.index[i])



Do anyone has an idea how to avoid that ?



Thanks in advance


Jessica

__
R-help@stat.math.ethz.ch 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] Sum per hour

2007-05-29 Thread jessica . gervais
Thank you,

I have try your proposition.

Seems to be the right way... but I still have an error message.

Here is the code I have executing:

time<-c("2000-10-03 14:00:00","2000-10-03 14:10:00","2000-10-03
14:20:00","2000-10-03 15:30:00","2000-10-03 16:40:00","2000-10-03
16:50:00","2000-10-03 17:00:00","2000-10-03 17:10:00","2000-10-03
17:20:00","2000-10-03 18:30:00","2000-10-04 14:00:00","2000-10-04
14:10:00","2000-10-04 14:20:00","2000-10-04 15:30:00","2000-10-04
16:40:00","2000-10-04 16:50:00","2000-10-04 17:00:00","2000-10-04
17:10:00","2000-10-04 17:20:00","2000-10-04 18:30:00")

precipitation<-c(0,0.1,0,0,0,0,0.2,0.3,0.5,6,7,8,9,1,0,0,0,0,1,0)

library(zoo)

z <- zoo(precipitation, as.POSIXct(time, tz = "GMT"))
aggregate(z, function(x) as.POSIXct(trunc(x, "hour")), sum(na.rm=TRUE))
Error in FUN(X[[1L]], ...) : argument "INDEX" is missing, with no default

...
I saw you can index a zoo object. I have tried with a vector..but doesn't
work.

I don't know else what this INDEX argument is...

Does anyone have an idea about it ?

Thanks in advance,

Jessica

__
R-help@stat.math.ethz.ch 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] Sum per hour

2007-05-24 Thread jessica . gervais

Dear all,

I have a list of precipitation record and a list of time
I would like to sum them up per hour, or per day.
Does such a function exist ?


example:
time<-c("2000-10-03 14:00:00","2000-10-03 14:10:00","2000-10-03
14:20:00","2000-10-03 15:30:00","2000-10-03 16:40:00","2000-10-03
16:50:00","2000-10-03 17:00:00","2000-10-03 17:10:00","2000-10-03
17:20:00","2000-10-03 18:30:00","2000-10-04 14:00:00","2000-10-04
14:10:00","2000-10-04 14:20:00","2000-10-04 15:30:00","2000-10-04
16:40:00","2000-10-04 16:50:00","2000-10-04 17:00:00","2000-10-04
17:10:00","2000-10-04 17:20:00","2000-10-04 18:30:00")

precipitation<-c(0,0.1,0,0,0,0,0.2,0.3,0.5,6,7,8,9,1,0,0,0,0,1,0)

DATA<-cbind(time,precipitation)

... ?
how to sum up per hour ?

Thanks in advance

Jessica

__
R-help@stat.math.ethz.ch 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] time series

2007-05-18 Thread jessica . gervais

Dear all,

I am working with a data file which is the record of precipitation
measurement normaly done every 10 minutes. I would like to check if there
are missing times in my data file.

Is there a function existing able to check for that in R ?

Thanks by advance,


Jessica

__
R-help@stat.math.ethz.ch 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] conversion into capital letter

2007-05-14 Thread jessica . gervais

Dear all,


I would need a function which convert small letter into capital letter (at
least the first letter of a character variable).

Does such a function exist in R ?

Thanks by advance

Jessica

__
R-help@stat.math.ethz.ch 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] plot time series

2007-05-08 Thread jessica . gervais
Dear all,

I actually would like to improve the label orientation on the x-axis (turn
them to 45 degrees)
I tried the par(las=2) ... but doesn't work...

Do anyone knows how to do ?

Jessica

__
R-help@stat.math.ethz.ch 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] plot time series

2007-05-08 Thread jessica . gervais
Dear All,

I sended my first mail as HTML by accident.
It has probably been stripped off... (see first mail below)
During that time, I was actually able to find a solution to my problem : I
wanted to plot times on a graph representing precipitation=f(time)


here is an example:

time<-c("2004-10-18 17:20:00","2004-10-18 17:50:00" ,"2004-10-18
18:40:00","2004-10-18 19:50:00","2004-10-18 20:00:00" ,"2004-10-18
20:10:00","2004-10-18 21:20:00" ,"2004-10-19 22:00:00" ,"2004-10-20
23:40:00")

precipitation<-c(0.1,0.5,0.0,0.8,1,2,5,9,1)

tt<-strptime(time,"%Y-%m-%d %H:%M:%S")
plot(tt,precipitation,xlab="time", xaxt="n")
r<-as.POSIXct(round(range(tt),"hours"))
axis.POSIXct(1,tt,at=seq(r[1],r[2],by="hour"),format="%Y-%m-%d %H:%M")

If you have better solution, I would be happy to know them,

Thanks in advance,

Jessica


-Jessica Gervais/CRTE/TUDOR wrote: -

To: R-help@stat.math.ethz.ch
From: Jessica Gervais/CRTE/TUDOR
Date: 05/08/2007 03:37PM
Subject: plot time series

Dear all,

I have a question concerning plotting time measurements.

I have a time serie which record precipitation at different time steps for
different meteo sations.
Data are stored into a table :
first column is time (time steps between 2 measurement are variables)
secondcolumn is the measurement
I would like to plot precipitation=f(time) and write time in axis. I can
not use the plot.ts function as time steps between 2 measurements are
variables. I don't want to do a plot.ts as time steps are variable and also
as I
would like the different times to be written on the x-axis.I also would
like space
between each time step on the x-axis to be representativ of the real
amount of time.

Here is a example

time<-c("2004-10-18 17:20:00","2004-10-18 17:50:00" ,"2004-10-18
18:40:00","2004-10-18 19:50:00","2004-10-18 20:00:00" ,"2004-10-18
20:10:00","2004-10-18 21:20:00" ,"2004-10-18 22:00:00" ,"2004-10-18
23:40:00")

(is it automatically recognized as a time format?)

precipitation<-c(0.1,0.5,0.0,0.8,1,2,5,0.2,3)

plot(time,precipitation)
Error in plot.window(xlim, ylim, log, asp, ...) :
need finite 'xlim' values
In addition: Warning messages:
1: NAs introduced by coercion
2: no non-missing arguments to min; returning Inf
3: no non-missing arguments to max; returning -Inf

Do anyone knows how to plot this kind os time dependant datas ?

Thanks in advance,

Regards,

Jessica

__
R-help@stat.math.ethz.ch 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] plot time series

2007-05-08 Thread jessica . gervais

__
R-help@stat.math.ethz.ch 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] extract arguments from a list

2006-10-19 Thread jessica . gervais
Hi,

I would like to know how to extract the arguments from a list :

For example, I have a list of charchacter x
x<- 
c("Bentazone","Atrazine","Epoxiconazol","Metolachlor","Epoxiconazol","Atrazine 
desethyl","Fenpropimorph","Epoxiconazol","Metolachlor","Simazine","Atrazine 
desethyl","Epoxiconazol","Atrazine 
desethyl","Atrazine","Epoxiconazol","Metolachlor","Epoxiconazol","Atrazine 
desethyl","Fenpropimorph","Epoxiconazol","Metolachlor","Simazine")
 
and I am searching for a (basic) function which would return arguments of 
the list x, aphabeticaly reordered like this :
 ("Atrazine","Atrazine 
desethyl","Bentazone","Epoxiconazol","Fenpropimorph","Metolachlor","Simazine").


Can anyone help me ?


Thanks by advance

Jessica



 
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] strip function

2006-10-04 Thread jessica . gervais
Hi,

I would like to asign titles into strip of a panel of curves designed 
thanks to a xyplot function (lattice package)
I ve tried the "strip" function, ...

here is my code
I would like to write in the strip of each panel conditionning varialbe 
(here, it is data[,1])
 xyplot (data[,3] ~ data[,2] | data[,1] ,  strip.default (which.given=1, 
which.panel = c(1:15), var.name= c 
("26","28","15","2","31","10","16","21","21.5","5","17","14","7","8","30"), 
factor.levels=c("26","28","15","2","31","10","16","21","21.5","5","17","14","7","8","30"),strip.names=c(1,0),strip.levels=c(0,0)),panel=function(x,y)
{
panel.xyplot(x,y,pch=4,col=3)
type = c("p", "r")
COEFF<-coef(lm(log(y)~x))
panel.curve(exp(COEFF[1]+COEFF[2]*x),col=4)
a<-round(COEFF[1],digit=2)
b<-round(COEFF[2],digit=2)
formula<-as.name(paste("y=exp(",a,b,"x)",sep=""))
panel.text(10,700,formula)
})


I cannot get anny result exept one page with a big strip on which is 
written 26 and then the curve without specified strip

CAn anyone give me some advices ?

Thanks by advance

Jessica Gervais

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] postcript file / xyplot function

2006-10-03 Thread jessica . gervais
Hi,

I  would like save a curve in a postscript file.

It when I use a common "plot" function (plot)

postscript(file="file.eps")
plot(x,y)
dev.off()

It's not working with the  "xyplot" function (lattice package).

postscript(file="Z",height=8,width=8,horizontal=FALSE)
xyplot(data[,3]~data[,2]|data[,1],panel=function(x,y){panel.xyplot(x,y)
COEFF<-coef(lm(log(y)~x))
panel.curve(exp(COEFF[1]+COEFF[2]*x))
dev.off()

Do anyone know how to use the postscript function with a xyplot function ?

Thanks by advance 

Jessica Gervais

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] panel.curve

2006-09-27 Thread jessica . gervais
Hi,

I am trying to fit experimental points by exponemtial curve

my data are stored into a matrix data

the first column is the geographical point (a number = data[,1] ) ( I 
would like to plot several graphes at  the same time)
the second column is the time of measurement (x in the plot)
the third column is a speed (y in the plot)

if we assume the point are folowing this exponential behaviour y=exp(a+bx)
then log y = a+ bx
we then can determine the coefficient a and b by a linear regression with 
the lm function and get them as following : coef ( lm (log(y)~x)) 
then I can use those coefficient


if I plot ln y = ax+b , everything goes fine 

 
xyplot(log(data[,3])~data[,2]|data[,1],panel=function(x,y){panel.xyplot(x,y)+panel.abline(coef(lm(y~x)))})
and I get perfect linear regression of my points

...But I would prefer to plot the exponential curves (y=exp ( a*x + b ))..
I tried the following formula :

> 
xyplot(data[,3]~data[,2]|data[,1],panel=function(x,y){panel.xyplot(x,y)+panel.curve(coef(lm(log(y)~x))[1])})

and I get : 
Error in model.frame(formula, rownames, variables, varnames, extras, 
extranames,  :
variable lengths differ (found for 'x')

... I don't really now what goes wrong and how to correct that
Maybe I am wrong in the use of the pannel.curve function  

Do anyone know something about that ? 


Thanks by advance

Jessica Gervais
 




[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] exponential fitting

2006-09-27 Thread jessica . gervais
Hi,

I would like to fit some experimental points by a exponential function. 
I ignore the parameters of this exponential and what I would like is to 
ask R to calculate the best fitting curve an the associated parameters (as 
the linear model function (lm) does for linear models). 
Is it possible ?
Do anyone have an idea about how to do that ?

Thanks by advance

Jessica Gervais


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] transformation matrice of vector into array

2006-07-27 Thread Jessica Gervais
Hi,

I need some help

I have a matrix M(m,n) in which each element is a vector V of lenght 6
 1  2  3  4  5  6  7
1   List,6 List,6 List,6 List,6 List,6 List,6 List,6
2   List,6 List,6 List,6 List,6 List,6 List,6 List,6
3   List,6 List,6 List,6 List,6 List,6 List,6 List,6
4   List,6 List,6 List,6 List,6 List,6 List,6 List,6


i would like to make the sum on the matrix of each element of the
matrix, that is to say 
sum(on the matrix)(M[j,][[j]][[1]])
sum(on the matrix)(M[j,][[j]][[2]])
...
sum(on the matrix)(M[j,][[j]][[6]])  

I don't really know how to do.
I thought it was possible to transform the matrix M into an array A of
dimension (m,n,6), and then use the command sum(colsums(A[,,1]), which
seems to be possible and quite fast.
...but I don't know how to convert a matrix of vector into an array

As anyone any little idea about that ?

Thanks by advance

Jessica

__
R-help@stat.math.ethz.ch 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.