[R] Aggregate records to 10min

2016-01-16 Thread Rolf Fankhauser

Hi

I would like to aggregate a rainfall series with 1min records (timestamp 
and value of 0.1mm from a tipping bucket raingauge) to 10min values by 
summing up the values.


# ptime is a POSIXlt datetime value with tz="GMT"

t10min <- 600*floor(as.integer(as.POSIXct(data$ptime))/600)
w10min <- tapply(data$value, format(as.POSIXct(t10min, tz="GMT", origin 
= "1970-01-01"), "%Y-%m-%d %H:%M"), sum)
write.table(as.matrix(w10min),"data 10min.txt", row.names=TRUE, 
col.names=FALSE, quote=FALSE)


This code works but I would like to have the result in datetime format 
of %m/%d/%Y %H:%M. When I output this format the records are not 
chronologically sorted but text-sorted because dimnames of w10min is of 
type character (because of the format function).

Is there an easier way summing up the records to 10min records?

Thanks,
Rolf

__
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] use gcheckbox in gWidgets to switch on/off gframe

2016-01-16 Thread Rolf Fankhauser

Hi Tonja

I removed the cat(...) in the event handlers because cat writes TRUE or 
FALSE to the console but doesn't seem to return a value.
Then it worked. You should initialize the frames to be disabled or the 
checkboxes to be checked that both states are consistant.


Regards, Rolf


tonja.krue...@web.de wrote:


Dear All,
I’m trying to create a GUI using gWidgets.
I would like to have a checkbox to “switch on/off” different frames within the 
GUI. Ideally if one frame is switched on, all other frames would be switched 
off.
Unfortunatly I only came as far as this:

library(gWidgets)
Population <- c("A","B","C","D","E","F")
w = gwindow("")
g1 = ggroup(horizontal = F, cont=w)
g2 = ggroup(horizontal = T, cont=g1)
glabel("Population:", cont=g2)
Station = gcombobox(Population, editable=F, cont=g2, handler=NULL)
gseparator(horizontal=T, container=g1, expand=F)
gcheckbox("checked", container=g1, handler=function(h,...) {
enabled ( frame1 ) <-  cat(svalue(h$obj))
})
frame1 <- gframe ( "A:" , cont = g1 , horizontal=FALSE )
lyt1 <- glayout ( cont = frame1)
widget_list <- list ( )
lyt1 [1,1] <- "A1:"
lyt1 [1,2,expand = TRUE] <- (widget_list$A1 <- gedit(" ", cont=lyt1, 
handler=NULL))
lyt1 [2,1] <- "A2:"
lyt1 [2,2,expand = TRUE] <- (widget_list$A2 <- gedit(" ", cont=lyt1, 
handler=NULL))
gcheckbox("checked", container=g1, handler=function(h,...) {
enabled ( frame2 ) <-  cat(svalue(h$obj))
})
frame2 <- gframe ( "B:" , cont = g1 , horizontal=FALSE )
lyt2 <- glayout ( cont = frame2)
widget_list <- list ( )
lyt2 [1,1] <- "B1:"
lyt2 [1,2, expand = TRUE] <- (widget_list$B1 <- gedit(" ", cont=lyt2, 
handler=NULL))

When I type in:
enabled ( frame2 ) <-  F; enabled ( frame2 ) <-  T
it does what I would like it to do. But when I check the checkbox it will only 
work once. Thank you for any suggestions!
Tonja

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



--
Rolf Fankhauser
Hegenheimerstrasse 129
4055 Basel
Tel. 061 321 45 25

__
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] Reading a tab delimted file of varying length using read.table

2016-01-17 Thread Rolf Fankhauser

Hello Pradeep

I downloaded divorce.dat but I could not find tabs between the columns.
You defined tab as separator, so your columns should be separated by tabs.
Therefore read.table reads the whole first line and wants to save the 
result as numeric because you defined the first column as numeric.


That's my interpretation
So, use tab, comma or semicolon as delimiter then it should work.

Rolf

Pradeep Bisht wrote:

Hello Experts  ,

Being a SAS developer I am finding it difficult to perform some of data
cleaning in R that are quite easy to perform in SAS .

I have been trying to read a .dat file and after a lot of attempts have
failed to find a solution . Maybe R doesn't have the functionality right
now or I am not looking in the right place . Here is my code .

f5=read.table("http://data.princeton.edu/wws509/datasets/divorce.dat

",
header=T,
sep="\t",
colClasses = c("numeric", "character", "character","character", "double",
"character" ) )
The error i get i
​s​
this .
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
:
scan() expected 'a real', got '912-15yearsNoNo10.546No'

Also does read.table always calls scan in background to do its job . If so
why use read.table in first place .

Pradeep​


__
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] use gcheckbox in gWidgets to switch on/off gframe

2016-01-22 Thread Rolf Fankhauser

Hi Tonja

Maybe I wasn't clear in my last post. This is the code:

library(gWidgetstcltk)
library(gWidgets)
options(guiToolkit="tcltk")
Population <- c("A","B","C","D","E","F")
w = gwindow("")
g1 = ggroup(horizontal = F, cont=w)
g2 = ggroup(horizontal = T, cont=g1)
glabel("Population:", cont=g2)
Station = gcombobox(Population, editable=F, cont=g2, handler=NULL)
gseparator(horizontal=T, container=g1, expand=F)
gcheckbox("checked", checked=T, container=g1, handler=function(h,...) {
enabled ( frame1 ) <- svalue(h$obj)
})
frame1 <- gframe ( "A:" , cont = g1 , horizontal=FALSE )
lyt1 <- glayout ( cont = frame1)
widget_list <- list ( )
lyt1 [1,1] <- "A1:"
lyt1 [1,2,expand = TRUE] <- (widget_list$A1 <- gedit(" ", cont=lyt1, 
handler=NULL))

lyt1 [2,1] <- "A2:"
lyt1 [2,2,expand = TRUE] <- (widget_list$A2 <- gedit(" ", cont=lyt1, 
handler=NULL))

gcheckbox("checked", checked=T, container=g1, handler=function(h,...) {
enabled ( frame2 ) <-  svalue(h$obj)
})
frame2 <- gframe ( "B:" , cont = g1 , horizontal=FALSE )
lyt2 <- glayout ( cont = frame2)
widget_list <- list ( )
lyt2 [1,1] <- "B1:"
lyt2 [1,2, expand = TRUE] <- (widget_list$B1 <- gedit(" ", cont=lyt2, 
handler=NULL))


Regards, Rolf

__
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 convert Datetime numbers from Excel to POSIXt objects

2007-12-14 Thread Rolf Fankhauser
Hi all,

I need to compare time series data files of different time formats. I 
had no problems with text format using strptime.
But how can I convert datetime numbers from Excel (days since 30.12.1899 
00:00:00) into POSIXt objects?
For example 29770.375 should be converted to  "03.07.1981 09:00:00"

I tried the following code and encountered strange results:

t1-t0 gives 29770.33 (should be 29770.375 in my opinion)
t1-t2 and t1-t3 are ok
t1-t4 gives 183. (should be 183.375)
Are these rounding errors?

The R-code:

t1 <- strptime("3.7.1981 09:00:00","%d.%m.%Y %H:%M:%S")
t0 <- strptime("30.12.1899 00:00:00","%d.%m.%Y %H:%M:%S")
t2 <- strptime("3.7.1981 00:00:00","%d.%m.%Y %H:%M:%S")
t3 <- strptime("1.7.1981 00:00:00","%d.%m.%Y %H:%M:%S")
t4 <- strptime("1.1.1981 00:00:00","%d.%m.%Y %H:%M:%S")
t1 - t0
t1 - t2
difftime(t1,t2,units="days")
t1 - t3
t1 - t4

Thanks for any help or clarifications

Rolf

__
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] How to convert Datetime numbers from Excel to POSIXt objects

2007-12-14 Thread Rolf Fankhauser
Ok, I see, the difference comes from summer and winter time. Thanks for 
the hint!
Stupid not to bear that in mind!!

Peter Dalgaard wrote:

>Rolf Fankhauser wrote:
>  
>
>>Hi all,
>>
>>I need to compare time series data files of different time formats. I 
>>had no problems with text format using strptime.
>>But how can I convert datetime numbers from Excel (days since 30.12.1899 
>>00:00:00) into POSIXt objects?
>>For example 29770.375 should be converted to  "03.07.1981 09:00:00"
>>
>>I tried the following code and encountered strange results:
>>
>>t1-t0 gives 29770.33 (should be 29770.375 in my opinion)
>>t1-t2 and t1-t3 are ok
>>t1-t4 gives 183. (should be 183.375)
>>Are these rounding errors?
>>  
>>1/(.375 - .33)
>>
>>
>[1] 23.99981
>
>So your expectation is off by 1/24th of a day.
>
>Can you think of something that might affect time differences by that
>amount, depending on which times of the year you are comparing?
>
>  
>
>>The R-code:
>>
>>t1 <- strptime("3.7.1981 09:00:00","%d.%m.%Y %H:%M:%S")
>>t0 <- strptime("30.12.1899 00:00:00","%d.%m.%Y %H:%M:%S")
>>t2 <- strptime("3.7.1981 00:00:00","%d.%m.%Y %H:%M:%S")
>>t3 <- strptime("1.7.1981 00:00:00","%d.%m.%Y %H:%M:%S")
>>t4 <- strptime("1.1.1981 00:00:00","%d.%m.%Y %H:%M:%S")
>>t1 - t0
>>t1 - t2
>>difftime(t1,t2,units="days")
>>t1 - t3
>>t1 - t4
>>
>>Thanks for any help or clarifications
>>
>>Rolf
>>
>>__
>>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@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.