R table()

Jmnote (토론 | 기여)님의 2019년 5월 11일 (토) 19:31 판

1 개요

R table()
벡터
x <- c(3,1,4,1,5,2,6,5)
table(x)
## x
## 1 2 3 4 5 6 
## 2 1 1 1 2 1
table( c(3,1,4,1,5,2,6,5) )
## 
## 1 2 3 4 5 6 
## 2 1 1 1 2 1
데이터프레임$컬럼
v <- c(1, 'hello', 1, 'world', 'hello')
table(v)
## v
##     1 hello world 
##     2     2     1
scores <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
Class  Name variable value
    A Alice  English    90
    A   Bob  English    80
    B  Dave  English    60
    A Alice     Math    60
    B Carol     Math    80
    B  Dave     Math    90
")
scores
##   Class  Name variable value
## 1     A Alice  English    90
## 2     A   Bob  English    80
## 3     B  Dave  English    60
## 4     A Alice     Math    60
## 5     B Carol     Math    80
## 6     B  Dave     Math    90

table( scores$variable )
## English    Math 
##       3       3 

table( scores$value )
## 60 80 90 
##  2  2  2
library(plyr)
table(baseball$year)
##
## 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 
##    7   13   13   15   17   15   17   17   25   28   36   35   38   53   50   51   56   60   57   72 
## 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 
##   77   75   68   67   70   74   75   79   77   69   83   87   79   81   82   81   82   81   82   75 
## 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 
##   86   99  101  108  133  122  112  110  124  117  117  115  133  132  137  136  134  133  132  133 
## 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 
##  125  132  133  133  127  134  121  118  130  122  132  120  101   90   89  122  124  112  120  120 
## 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 
##  126  143  141  139  162  173  173  175  184  199  198  192  200  219  218  230  227  214  253  268 
## 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 
##  274  282  295  300  308  315  323  309  319  298  307  316  318  316  315  329  330  326  339  333 
## 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 
##  333  351  355  333  363  343  335  324  283  285  261  213  216  187  160  141   92

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}