I am having issues labeling the breaks (or intervals) when using the cut function.
Here are some sample data (the actual dataset has over 22,000 entries ranging from 1899-2014 within a dataframe with a total of 12 vectors):
x <- c(1899,1900,2001,2012,1999,1943,1944,1950,1988,1981,1988,1997,2014)
I'd like to categorize these by decade (eg. 1890s includes 1890 through 1899). I am able to make the breaks using the following code:
decade_vector <- cut(x, breaks = c(1889,1899,1909,1919,1929,1939,1949,
1959,1969,1979,1989,1999,2009,2019))
However, when I go to label these breaks using the following code:
decade_vector <- cut(x, breaks = c(1889,1899,1909,1919,1929,1939,1949,
1959,1969,1979,1989,1999,2009,2019),
labels = c("1890s","1900s","1910s","1920s","1930s",
"1940s","1950s","1960s","1970s","1980s",
"1990s","2000s","2010s"),
ordered=TRUE))
I get:
Warning message:
In is.factor(x) : NAs introduced by coercion
I created a dataframe and wrote it to csv, and when I look at it I don't see any NAs, but the labels are not there.
Can someone let me know what I'm doing wrong? I'd like to get various stats by decade, but I can't seem to figure out what I am missing here.
Any help would be super appreciated!
Thanks!