# Re: [R] table questions

From: Ted Harding <Ted.Harding_at_manchester.ac.uk>
Date: Wed, 30 Jul 2008 01:14:45 +0100 (BST)

On 29-Jul-08 16:28:26, Edna Bell wrote:
> Hi again!
> Suppose I have the following:
>

```>> xy <- round(rexp(20),1)
>> xy
```

> [1] 0.1 3.4 1.6 0.4 1.0 1.4 0.2 0.3 1.6 0.2 0.0 0.1 0.1 1.0 2.0 0.9
> 2.5 0.1 1.5 0.4
```>> table(xy)
```

> xy
> 0 0.1 0.2 0.3 0.4 0.9 1 1.4 1.5 1.6 2 2.5 3.4
> 1 4 2 1 2 1 2 1 1 2 1 1 1
```>>
```

> Is there a way to set things up to have
> 0 - 0.4 0.5 - 0.9 etc. please?
>
> I know there is the cut functions, but breaks are required. If you
> don't have breaks, what should you do, please?
>
> Would using the breaks from the hist function work appropriately,
>
> thanks
> Edna Bell

It could, though it seems a bit clumsy:

xy<-round(rexp(20),1)
H<-hist(xy,breaks=(-0.05+0.5*(0:8)),plot=FALSE)   brks<-H\$breaks ; cts<-H\$counts
Tbl<-rbind(NULL,cts)
brlabs<-paste(brks[1:(k-1)]+0.05,"-",brks[2:k]-0.05,sep="")   colnames(Tbl)<-brlabs
Tbl
# 0-0.4 0.5-0.9 1-1.4 1.5-1.9 2-2.4 2.5-2.9 3-3.4 3.5-3.9 #cts 5 4 6 3 0 1 1 0

One could fiddle with formatting to replace 0 by 0.0 and 3 by 3.0, and set rownames=NULL; but I don't see how to get the counts placed in the "middle" of the range. But it's better than nothing, I suppose!

Ted.

E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861
```Date: 30-Jul-08                                       Time: 01:14:43
------------------------------ XFMail ------------------------------

______________________________________________
```
R-help_at_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. Received on Wed 30 Jul 2008 - 00:20:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Jul 2008 - 00:33:01 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.