On 12/17/2013 05:50 PM, ???????? wrote:
Mydata is as under.
dat=" salary ex
+ 1 1856 1799
+ 2 1856 1800
+ 3 1858 1800
+ 4 1858 1801
+ 5 1862 1803
+ 6 1862 1805
+ 7 1862 1810
+ 8 1865 1805
+ 9 1865 1808
+ 10 1865 1815
+ 11 1865 1820
+ 12 1870 1810
+ 13 1870 1830
+ 14 1880 1840
+ 15 1880 1845
+ 16 1880 1851
+ 17 1880 1853
+ 18 1880 1855
+ 19 1885 1850
+ 20 1885 1852
+ 21 1885 1857
+ 22 1885 1860
+ 23 1898 1855
+ 24 1898 1858
+ 25 1898 1861
+ 26 1898 1863
+ 27 1898 1866
+ 28 1898 1867
+ 29 1898 1890
+ 30 1902 1850
+ 31 1902 1853
+ 32 1902 1869
+ 33 1902 1872
+ 34 1902 1873
+ 35 1915 1850
+ 36 1915 1859
+ 37 1915 1863
+ 38 1915 1868
+ 39 1915 1875
+ 40 1915 1898
+ "
data<-read.table(text=dat,header=TRUE)
I want to get the result(please see the attatchment),the header is salary,the
rownames is ex.
I only can get the "total column"
rev(table(cut(data[,2],breaks=seq(1795,1905,10),right=F)))
How can I get the other data by some code,not by hand?
Hi ????????,
Your attachment didn't make it to the list, so we don't know exactly
what you want to do. The code above produces a table of the frequencies
of the categories you have defined:
rev(table(cut(dat[,2],breaks=seq(1795,1905,10),right=FALSE)))
[1895,1905) [1885,1895) [1875,1885) [1865,1875) [1855,1865) [1845,1855)
1 1 1 6 9 8
[1835,1845) [1825,1835) [1815,1825) [1805,1815) [1795,1805)
1 1 2 5 5
Do you want a summary function applied to the first column?
dat$cats<-cut(dat[,2],breaks=seq(1795,1905,10),right=FALSE)
by(dat$salary,dat$cats,mean)
or some other sort of result?
Jim
______________________________________________
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.