본문 바로가기
  • Homines, dum docent, discunt
  • Repetitio est Mater Memoriae
  • Dilige et fac quod vis
지식 창고/R 언어

R Script Note

by Manana Cho 2021. 9. 4.
반응형

library(tidyverse)
library(DBI)
view(CO2)

#9-1: Write R code to obtain total CO2 uptake by plant.
by_plant<-group_by(CO2,Plant)
uptake_total<-summarize(by_plant,totalUptake=sum(uptake))
view(uptake_total)

#9-2: Sort CO2 data by CO2 uptake in ascending order
arrange(CO2,uptake)

#9-3: Write R code to find the number of records for each "Type"
by_type<-group_by(CO2,Type)
count_type<-unique(summarize(by_type,count(by_type)))
view(count_type)

#9-4: Write R code to calculate total CO2 uptake by each Type and Treatment 
Treatment_by_Type<-CO2 %>%
  group_by(Treatment, Type) %>%
  summarize(totalUptake=sum(uptake))
view(Treatment_by_Type)

#9-5: Write R code to calculate average concentration (conc) for each Type
by_type<-group_by(CO2,Type)
avg_conc<-summarize(by_type,avg_conc=mean(conc))
view(avg_conc)

반응형

댓글