Re: [R] Count observation based on hour

2014-02-08 Thread arun
Hi,
Try:
#using the same `data`

 res1 - 
as.data.frame(table(with(dat,cut(Date,breaks=seq(as.POSIXct(2013-01-01 
00:00:00),max(Date)+3600,by='1 hour')


A.K.



Hi A.K. 

Thank you very much! It worked!!  Just another quick follow-up question: 

res - as.data.frame(table( 
with(dat,cut(Date,breaks=seq(min(Date),max(Date)+3600,by= '1 hour') 

Is it possible to set the min in the seq() to a specific date-time say 
2013-01-01 00:00:00?   

Thank you again for your help! 

Map 




On Thursday, February 6, 2014 5:34 PM, arun smartpink...@yahoo.com wrote:
HI Map,
I am not sure what you really wanted.  Perhaps, this helps:

dat - structure(list(Date = c(2014-01-01 00:00:00, 2014-01-02 11:00:00, 
2014-01-02 22:00:00, 2014-01-03 03:00:00, 2014-01-01 00:00:00, 
2014-02-02 11:00:00, 2014-02-02 22:00:00, 2014-02-03 03:00:00, 
2014-02-01 00:00:00, 2014-03-01 11:00:00, 2014-03-02 22:00:00, 
2014-03-03 03:00:00, 2014-03-01 00:00:00, 2014-03-01 11:00:00, 
2014-03-02 22:00:00, 2014-01-03 03:00:00)), .Names = Date, class = 
data.frame, row.names = c(1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16))
dat$Date - as.POSIXct(dat$Date)
res - as.data.frame(table( 
with(dat,cut(Date,breaks=seq(min(Date),max(Date)+3600,by= '1 hour')
A.K.



Hi AK, 

Thanks for the tips! But it doesn't seem to work for some 
reasons.  Basically I want to do a time series analysis and I heard that
it is actually very easy to perform hourly count, e.g. count the number
of occurrence hourly when the variable is in date-time format like 
this: -MM-DD HH:MM:SS.   

I was thinking a 'long' way (sorry for this if it sounds stupid 
:p) by dividing my data into say 1000 24-hr (i.e. one day) sections, 
count them all them merge... Anyway, could you give me more advice on 
this please?  Thanks! 

Map 




On Wednesday, February 5, 2014 10:59 AM, arun smartpink...@yahoo.com wrote:
Hi,
Try:

data.frame(table(dat$Date))
A.K.


Hi guys, I have some 20,000 observations like this: 
          Date       
2014-01-01 00:00:00 
2014-01-02 11:00:00 
2014-01-02 22:00:00 
2014-01-03 03:00:00 

I want to perform an hourly count (e.g. the frequency occur at 
each hour for a specific date) so the result would look like this: 

          Date                    Frequency 
2014-01-01 00:00:00             1 
2014-01-01 01:00:00             1 
2014-01-01 02:00:00             1 
2014-01-01 03:00:00             1 

Any suggestions?  Thanks!

__
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] Count observation based on hour

2014-02-06 Thread arun
HI Map,
I am not sure what you really wanted.  Perhaps, this helps:

dat - structure(list(Date = c(2014-01-01 00:00:00, 2014-01-02 11:00:00, 
2014-01-02 22:00:00, 2014-01-03 03:00:00, 2014-01-01 00:00:00, 
2014-02-02 11:00:00, 2014-02-02 22:00:00, 2014-02-03 03:00:00, 
2014-02-01 00:00:00, 2014-03-01 11:00:00, 2014-03-02 22:00:00, 
2014-03-03 03:00:00, 2014-03-01 00:00:00, 2014-03-01 11:00:00, 
2014-03-02 22:00:00, 2014-01-03 03:00:00)), .Names = Date, class = 
data.frame, row.names = c(1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16))
dat$Date - as.POSIXct(dat$Date)
res - as.data.frame(table( 
with(dat,cut(Date,breaks=seq(min(Date),max(Date)+3600,by= '1 hour')
A.K.



Hi AK, 

Thanks for the tips! But it doesn't seem to work for some 
reasons.  Basically I want to do a time series analysis and I heard that
 it is actually very easy to perform hourly count, e.g. count the number
 of occurrence hourly when the variable is in date-time format like 
this: -MM-DD HH:MM:SS.   

I was thinking a 'long' way (sorry for this if it sounds stupid 
:p) by dividing my data into say 1000 24-hr (i.e. one day) sections, 
count them all them merge... Anyway, could you give me more advice on 
this please?  Thanks! 

Map 



On Wednesday, February 5, 2014 10:59 AM, arun smartpink...@yahoo.com wrote:
Hi,
Try:

data.frame(table(dat$Date))
A.K.


Hi guys, I have some 20,000 observations like this: 
          Date       
2014-01-01 00:00:00 
2014-01-02 11:00:00 
2014-01-02 22:00:00 
2014-01-03 03:00:00 

I want to perform an hourly count (e.g. the frequency occur at 
each hour for a specific date) so the result would look like this: 

          Date                    Frequency 
2014-01-01 00:00:00             1 
2014-01-01 01:00:00             1 
2014-01-01 02:00:00             1 
2014-01-01 03:00:00             1 

Any suggestions?  Thanks!
__
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] Count observation based on hour

2014-02-05 Thread arun
Hi,
Try:

data.frame(table(dat$Date))
A.K.


Hi guys, I have some 20,000 observations like this: 
          Date       
2014-01-01 00:00:00 
2014-01-02 11:00:00 
2014-01-02 22:00:00 
2014-01-03 03:00:00 

I want to perform an hourly count (e.g. the frequency occur at 
each hour for a specific date) so the result would look like this: 

          Date                    Frequency 
2014-01-01 00:00:00             1 
2014-01-01 01:00:00             1 
2014-01-01 02:00:00             1 
2014-01-01 03:00:00             1 

Any suggestions?  Thanks!

__
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] Count observation

2009-06-11 Thread MarcioRibeiro

Hi listers,
I have the following code...

data-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
n-nrow(data)
m-n-1
boot-data[sample(m,replace=T),]

So, I need to count the number of times each observation was selected at the
sample with replacement...
Suppose I sampled...
4 5 1 3 7 5 1 4 7

So, I would count...
x  count
1  2
2  0
3  1
4  2
5  2
6  0
7  2
8  0
9  0
10 0

Thanks in advance,
Marcio
-- 
View this message in context: 
http://www.nabble.com/Count-observation-tp23987251p23987251.html
Sent from the R help mailing list archive at Nabble.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] Count observation

2009-06-11 Thread milton ruser
Hi Marcio,

data.frame(table(boot))
?

milton
brazil=toronto
On Thu, Jun 11, 2009 at 3:13 PM, MarcioRibeiro mes...@pop.com.br wrote:


 Hi listers,
 I have the following code...

 data-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
 n-nrow(data)
 m-n-1
 boot-data[sample(m,replace=T),]

 So, I need to count the number of times each observation was selected at
 the
 sample with replacement...
 Suppose I sampled...
 4 5 1 3 7 5 1 4 7

 So, I would count...
 x  count
 1  2
 2  0
 3  1
 4  2
 5  2
 6  0
 7  2
 8  0
 9  0
 10 0

 Thanks in advance,
 Marcio
 --
 View this message in context:
 http://www.nabble.com/Count-observation-tp23987251p23987251.html
 Sent from the R help mailing list archive at Nabble.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.htmlhttp://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
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] Count observation

2009-06-11 Thread Jorge Ivan Velez
Dear Marcio,
Here is one way. Please notice that even thought I changed the name of your
data as well as its structure, you can easily modify it to your needs.

# Data
somedata - 1:10
n-length(somedata)
m-n-1

# 1 sample
boot - somedata[ sample(m,replace=T) ]
table(factor( boot, levels=1:10 ) )

# 100 samples
boots - replicate(100, somedata[ sample(m,replace=T)] )

# The counts
apply(boots, 2, function(x) table(factor(x,levels=1:10)) )

see ?replicate, and ?apply for more information.

HTH,

Jorge



On Thu, Jun 11, 2009 at 3:13 PM, MarcioRibeiro mes...@pop.com.br wrote:


 Hi listers,
 I have the following code...

 data-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
 n-nrow(data)
 m-n-1
 boot-data[sample(m,replace=T),]

 So, I need to count the number of times each observation was selected at
 the
 sample with replacement...
 Suppose I sampled...
 4 5 1 3 7 5 1 4 7

 So, I would count...
 x  count
 1  2
 2  0
 3  1
 4  2
 5  2
 6  0
 7  2
 8  0
 9  0
 10 0

 Thanks in advance,
 Marcio
 --
 View this message in context:
 http://www.nabble.com/Count-observation-tp23987251p23987251.html
 Sent from the R help mailing list archive at Nabble.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.


[[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] Count observation

2009-06-11 Thread MarcioRibeiro

Hey... Milton...
Is that a equation... Brazil=Toronto
If so, mine is... Brazil=Montreal
You got it...
I am not having a good time with R... There is no help for data manipulation
at all...
Thanks for the help... 
Marcio



milton ruser wrote:
 
 Hi Marcio,
 
 data.frame(table(boot))
 ?
 
 milton
 brazil=toronto
 On Thu, Jun 11, 2009 at 3:13 PM, MarcioRibeiro mes...@pop.com.br wrote:
 

 Hi listers,
 I have the following code...

 data-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
 n-nrow(data)
 m-n-1
 boot-data[sample(m,replace=T),]

 So, I need to count the number of times each observation was selected at
 the
 sample with replacement...
 Suppose I sampled...
 4 5 1 3 7 5 1 4 7

 So, I would count...
 x  count
 1  2
 2  0
 3  1
 4  2
 5  2
 6  0
 7  2
 8  0
 9  0
 10 0

 Thanks in advance,
 Marcio
 --
 View this message in context:
 http://www.nabble.com/Count-observation-tp23987251p23987251.html
 Sent from the R help mailing list archive at Nabble.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.htmlhttp://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
 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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Count-observation-tp23987251p23988982.html
Sent from the R help mailing list archive at Nabble.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] Count observation

2009-06-11 Thread Henrique Dallazuanna
Try this also:

cbind(data, tabulate(boot, nbins=nrow(data)))

On Thu, Jun 11, 2009 at 4:13 PM, MarcioRibeiro mes...@pop.com.br wrote:


 Hi listers,
 I have the following code...

 data-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
 n-nrow(data)
 m-n-1
 boot-data[sample(m,replace=T),]

 So, I need to count the number of times each observation was selected at
 the
 sample with replacement...
 Suppose I sampled...
 4 5 1 3 7 5 1 4 7

 So, I would count...
 x  count
 1  2
 2  0
 3  1
 4  2
 5  2
 6  0
 7  2
 8  0
 9  0
 10 0

 Thanks in advance,
 Marcio
 --
 View this message in context:
 http://www.nabble.com/Count-observation-tp23987251p23987251.html
 Sent from the R help mailing list archive at Nabble.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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

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