[R] how to enter frequency type data in R with class intervals

David Winsemius dwinsemius at comcast.net
Sun Jan 30 17:18:40 CET 2011


On Jan 30, 2011, at 5:48 AM, arindam fadikar wrote:

> Dear all,
>
> Given data of a continuous frequency distribution with class  
> intervals ..
> how to enter such data so that we can use the normal mean, median  
> and mode
> functions to calculate them and also can draw histogram ..
>
> for example how to enter this data in R
>
>  Height range[image:
> ↓]<http://en.wikipedia.org/wiki/Frequency_distribution#> Number
> of students[image: ↓]
> <http://en.wikipedia.org/wiki/Frequency_distribution#> Cumulative
> number[image: ↓] <http://en.wikipedia.org/wiki/ 
> Frequency_distribution#> 4.5–5.0
> feet 25 25 5.0–5.5 feet 35 60 5.5–6 feet 20 80 6.0–6.5 feet 20  
> 100

The textConnection function allows you to simulate file input from  
material cut and pasted from text sources:

 > dtabl <- read.table(textConnection("4.5–5.0 feet 25 25 \n5.0–5.5  
feet 35 60 \n5.5–6 feet 20 80 \n6.0–6.5 feet 20 100"),  
header=FALSE, stringsAsFactors=FALSE)
 > names(dtabl) <- c("Interval", "units", "Freq", "Cum_Freq")
 > dtabl
   Interval units Freq Cum_Freq
1  4.5–5.0  feet   25       25
2  5.0–5.5  feet   35       60
3    5.5–6  feet   20       80
4  6.0–6.5  feet   20      100

You may need to remove extraneous linefeeds inserted by our mail  
clients.

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list