docvars-internal.Rd
Extract methods for docvars
# S3 method for corpus $(x, name) # S3 method for corpus $(x, name) <- value # S3 method for tokens $(x, name) # S3 method for tokens $(x, name) <- value # S3 method for dfm $(x, name) # S3 method for dfm $(x, name) <- value
x | corpus, tokens, or dfm object whose document-level variables will be read or set |
---|---|
name | a literal character string specifying a single docvars name |
value | a vector of document variable values to be assigned to |
# accessing or assigning docvars for a corpus using "$" data_corpus_inaugural$Year#> [1] 1789 1793 1797 1801 1805 1809 1813 1817 1821 1825 1829 1833 1837 1841 1845 #> [16] 1849 1853 1857 1861 1865 1869 1873 1877 1881 1885 1889 1893 1897 1901 1905 #> [31] 1909 1913 1917 1921 1925 1929 1933 1937 1941 1945 1949 1953 1957 1961 1965 #> [46] 1969 1973 1977 1981 1985 1989 1993 1997 2001 2005 2009 2013 2017data_corpus_inaugural$century <- floor(data_corpus_inaugural$Year / 100) data_corpus_inaugural$century#> [1] 17 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 #> [26] 18 18 18 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 #> [51] 19 19 19 20 20 20 20 20# accessing or assigning docvars for tokens using "$" toks <- tokens(corpus_subset(data_corpus_inaugural, Year <= 1805)) toks$Year#> [1] 1789 1793 1797 1801 1805toks$Year <- 1991:1995 toks$Year#> [1] 1991 1992 1993 1994 1995#> Year President FirstName Party century nonexistent #> 1 1991 Washington George none 17 TRUE #> 2 1992 Washington George none 17 TRUE #> 3 1993 Adams John Federalist 17 TRUE #> 4 1994 Jefferson Thomas Democratic-Republican 18 TRUE #> 5 1995 Jefferson Thomas Democratic-Republican 18 TRUE#> [1] 1991 1992 1993 1994 1995dfmat$Year <- 1991:1995 dfmat$Year#> [1] 1991 1992 1993 1994 1995#> Year President FirstName Party century nonexistent #> 1 1991 Washington George none 17 TRUE #> 2 1992 Washington George none 17 TRUE #> 3 1993 Adams John Federalist 17 TRUE #> 4 1994 Jefferson Thomas Democratic-Republican 18 TRUE #> 5 1995 Jefferson Thomas Democratic-Republican 18 TRUE