Hi. I have a seemingly simple question. I have scoured the boards, and could not find specific answer; usually the questions are more complex.
My data are composed of 17 sites with 80 land use categories, and percent of landuse . I simply want to get the average land use and SD for the categories. I made categories a factor. My code ran fine. But the output put the categories in alphabetical order. I tried multiple solutions (arrange(categories), or using levels=categories.in.order.
I just want to get the output for the categories in the original order, as described in the data.
Thanks!
Code:#### Summary statistics for categories
landuse_summary <- landuse.test %>%
group_by(categories) %>%
summarise(
Observations = n(),
Means = mean(percent),
St.dev =sd(percent)) %>%
arrange(desc(categories))
#> Error in landuse.test %>% group_by(categories) %>% summarise(Observations = n(), : could not find function "%>%"
landuse_summary$categories <- landuse_summary$categories %>% factor(levels=categories.in.order, ordered=TRUE)
#> Error in landuse_summary$categories %>% factor(levels = categories.in.order, : could not find function "%>%"
And my data, should be the first 20 rows--there are 920 rows for full set
data.frame(
stringsAsFactors = FALSE,
Name = c("Street1","Street1",
"Street1","Street1","Street1","Street1","Street1",
"Street1","Street1","Street1","Street1","Street1",
"Street1","Street1","Street1","Street1","Street1",
"Street1","Street1","Street1"),
categories = c("OSTDS",
"Residential.Low.Density","Residential.Medium.Density",
"Residential.High.Density","Total.residential",
"Commercial.and.Services","Industrial","Institutional","Total.commercial",
"Recreational","Open.Land",
"Cropland.and.Pastureland","Tree.Crops","Nurseries.and.Vineyards",
"Specialty.Farms","Total.Agriculture","Other.Open.Lands..Rural.",
"Total.Rural","Herbaceous","Shrub.and.Brushland"),
percent = c(372,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,17.65653533)
)