Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getwd()
- options(scipen = 999) #this prevents conversion to scientific notation
- # putting a HASHTAG or number sign prevents everything
- # to the right on that line from being run
- '''
- For comments that are too long to be a single line
- one can insert 3 single quote marks like
- i did here.
- '''
- library(tidyverse)
- library(lubridate)
- #library(readODS)
- ############### DATA: https://databank.worldbank.org/reports.aspx?source=world-development-indicators#
- data<- read_csv("Data_2.csv")
- View(data) # See the data in its entiruity
- dim(data) # rowss & columns
- head(data, 5) # see the first 5 rows.(Ommit 5 and defaults to 10)
- tail(data) # you guessed it
- glimpse(data) # pointless option
- ls(data) #list of variables
- A<- data
- A<- data%>%
- rename(variable = Years)
- #US_deaths<- US_deaths %>%
- #rename(Country = Entity ,Deaths = `Daily confirmed deaths (deaths)`)
- skinny_2<- A%>%
- gather("year" , "value", -variable)
- skinny_1<- A%>%
- gather("category" , "value", -Years)
- skinny_1
- View(skinny_1)
- #skinny_1 <- pivot_longer(data, c( 1960,1961,1962,1963,1964,1965,1966,1967,1968,
- 1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980))
- #skinny_1<- pivot_longer(data, c(`1960` : `1980`))
- #skinny_1 <- data%>%
- mutate_if(is.numeric,as.character, is.factor, as.character) %>%
- pivot_longer( names_to = "key",
- values_to = "val")
- #small_diamonds %>%
- small_diamonds %>%
- mutate_if(is.numeric,as.character, is.factor, as.character) %>%
- pivot_longer( - row_num,
- names_to = "key",
- values_to = "val")
- stocks <- tibble(
- time = as.Date('2009-01-01') + 0:9,
- X = rnorm(10, 0, 1),
- Y = rnorm(10, 0, 2),
- Z = rnorm(10, 0, 4)
- )
- stocks
- gather(stocks, "stock", "price", -time)
- test<- read_csv("test_data.csv")
- test$year <- as.Date(as.character(test$year) , format = "%Y")
- test$pop <- as.numeric(test$pop)
- test$city<- as.factor(test$city)
- p<- ggplot(test, aes(year , pop, color = city, group = city))+
- geom_line()
- p
- str(test)
- Boston<-
- filter(test, city == "Boston")
- Boston
- p<- ggplot(Boston, aes(year , pop))+
- geom_line()
- p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement