R(week 13)

d <- sample(1:10, 7)
d
sort(d, decreasing = TRUE)
tmpIndex <- order(d)
d[tmpIndex]

tmpIndex <- order(airquality$Wind)
tmpIndex

scoreSheet1 <- data.frame(stName = c("sdfs", "dsfsd", "saa", "bb", "aa"), 
              semester = c(rep(1, 5), rep(2, 5)), English = round(rnorm(10, 75, 4)),
              Chinese = round(rnorm(10, 80, 10)))
scoreSheet1
aggregate(Chinese ~ semester, data = scoreSheet1, FUN = mean)

library(tidyverse)

sheet1 <- data.frame(stName = c("sdfs", "dsfsd", "saa", "bb", "aa"), 
                          semester = c(rep(1, 5), rep(2, 5)), English = round(rnorm(10, 75, 4)),
                          Chinese = round(rnorm(10, 80, 10)))
view(sheet1)

sheet2 <- gather(sheet1, key = course, 
                 value = score, English, Chinese)
sheet2
view(sheet2)

sheet2$semester <- as.factor(sheet2$semester)

ggplot(sheet2, aes(x = course, y = score, fill = semester)) + 
  geom_boxplot()

sheet3 <- spread(sheet2, key = course, 
                  value = score)

view(sheet3)

group_by(airquality, Month) %>%
  summarise(mean(Wind))

  

posted @ 2021-05-24 17:44  sinEagle  阅读(35)  评论(0编辑  收藏  举报