help required state wise count

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

help required state wise count

mohan L
I have the data like this:

> dummy
   State Months No
1    xxx    Jan  1
2    xxx    Jan  2
3    xxx    Jan  1
4    yyy    Jan  1
5    yyy    Jan  2
6    yyy    Jan  1
7    zzz    Jan  3
8    zzz    Jan  1
9    zzz    Jan  2
10   xxx    Feb  3
11   xxx    Feb  4
12   xxx    Feb  2
13   yyy    Feb  1
14   yyy    Feb  2
15   yyy    Feb  1
16   zzz    Feb  2
17   zzz    Feb  3
18   zzz    Feb  3

I want for a month Jan how many count(row) is there for xxx and yyy.some
thing like this:

State Jan  Feb  Mar
xxx   3     3
yyy   3     3
zzz   3     3

Any clue will be greatly appreciated

Thanks & Rg
Mohan L

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: help required state wise count

Jim Lemon
On 05/24/2010 07:44 PM, Mohan L wrote:

> I have the data like this:
>
>> dummy
>     State Months No
> 1    xxx    Jan  1
> 2    xxx    Jan  2
> 3    xxx    Jan  1
> 4    yyy    Jan  1
> 5    yyy    Jan  2
> 6    yyy    Jan  1
> 7    zzz    Jan  3
> 8    zzz    Jan  1
> 9    zzz    Jan  2
> 10   xxx    Feb  3
> 11   xxx    Feb  4
> 12   xxx    Feb  2
> 13   yyy    Feb  1
> 14   yyy    Feb  2
> 15   yyy    Feb  1
> 16   zzz    Feb  2
> 17   zzz    Feb  3
> 18   zzz    Feb  3
>
> I want for a month Jan how many count(row) is there for xxx and yyy.some
> thing like this:
>
> State Jan  Feb  Mar
> xxx   3     3
> yyy   3     3
> zzz   3     3
>
Hi Mohan,
Try this:

table(dummy$State,dummy$Months)

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: help required state wise count

mohan L
>>
>>  Hi Mohan,
> Try this:
>
> table(dummy$State,dummy$Months)
>
> Jim
>
> Thanks for your time.
table(dummy$State,dummy$Months)

in this case the state column becomes the row index. I want the state name
as the first column. There may be a way to do it.

Thanks & Rg
Mohan L

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: help required state wise count

David Winsemius

On May 24, 2010, at 8:21 AM, Mohan L wrote:

>>>
>>> Hi Mohan,
>> Try this:
>>
>> table(dummy$State,dummy$Months)
>>
>> Jim
>>
>> Thanks for your time.
> table(dummy$State,dummy$Months)
>
> in this case the state column becomes the row index. I want the  
> state name
> as the first column. There may be a way to do it.

?as.data.frame

>
> Thanks & Rg
> Mohan L

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: help required state wise count

Jim Lemon
In reply to this post by mohan L
On 05/24/2010 10:21 PM, Mohan L wrote:
> ...
> in this case the state column becomes the row index. I want the state
> name as the first column. There may be a way to do it.
>
Hi Mohan,
You can do it with this awful kludge, but there must be a better way:

dummy<-data.frame(
  State=sample(c("NSW","NT","QLD","SA","TAS","WA"),100,TRUE),
  Month=sample(c("Jan","Feb","Mar","Apr","May","Jun",
   "Jul","Aug","Sep","Oct","Nov","Dec"),100,TRUE))
dummytab<-table(dummy$State,dummy$Month)
dfdummytab<-data.frame(State=rownames(dummytab),
  Jan=dummytab[,5],Feb=dummytab[,4],Mar=dummytab[,8],
  Apr=dummytab[,1],May=dummytab[,9],Jun=dummytab[,7],
  Jul=dummytab[,6],Aug=dummytab[,2],Sep=dummytab[,12],
  Oct=dummytab[,11],Nov=dummytab[,10],Dec=dummytab[,3])
rownames(dfdummytab)<-NULL

Jim

______________________________________________
[hidden email] 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.