Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

ASSIGNMENT 12

Shreshth Malhotra

2024-03-21
#Q1) Creating a dataframe.
#connection_no <- c(1:20)
#customer_name <-
c("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s"
,"t")
#village <-
c("aaa","bbb","ccc","ddd","eee","fff","ggg","hhh","iii","jjj","kkk","lll","mm
m","nnn","ooo","ppp","qqq","rrr","sss","ttt")
#month <-
c("jan","feb","march","april","may","june","july","aug","sep","oct","nov","de
c","jan","feb","march","april","may","june","july","aug")
#week1 <- c(10,20,30,40,50,60,70,30,40,20,10,50,90,70,50,20,40,80,30,20)
#week2 <- c(30,60,30,90,50,80,20,10,40,60,90,20,80,40,10,30,50,70,80,10)
#week3 <- c(60,50,40,90,10,50,30,70,90,40,50,50,30,10,20,30,50,70,90,40)
#week4 <- c(70,20,50,90,10,20,90,30,80,40,70,50,60,10,90,20,80,30,70,40)
#year <-
c(2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,
2016,2017,2018,2019,2020)
#total_units=week1+week2+week3+week4
#bill_amount=total_units

#Electricity_bill <-
data.frame(connection_no,customer_name,village,month,week1,week2,week3,week4,
year,total_units,bill_amount)
#Electricity_bill

#Q3) Using the gather function to combine week1 and week2.


#week12 <- Electricity_bill %>%
#gather(week12, Frequency, week1:week2)
#week12

#Q4) Using the gather function to combine week3 and week4.


#week34 <- Electricity_bill %>%
#gather(week34, frequency, week3:week4)
#week34
#Q5) Using the separate function.
#separate_data <- week34 %>%
#separate(week34, c("FirstHalf", "SecondHalf"))
#separate_data

#Q6) Using the unite function.


#unite_data <- separate_data %>%
#unite(week34,FirstHalf, SecondHalf, sep="_")
#unite_data

#Q7) Using the spread function to rearrange data.


#rearranged_data <- unite_data %>%
#spread(week34, frequency)
#rearranged_data

#Q8) Using the fill function.


#year <-
c(2001,NA,2003,2004,2005,2006,2007,2008,NA,2010,2011,2012,NA,2014,2015,NA,201
7,2018,2019,NA)

#Electricity_bill <-
data.frame(connection_no,customer_name,village,month,week1,week2,week3,week4,
year,total_units,bill_amount)
#Electricity_bill

#Electricity_bill %>% fill(year)

#Q9) Dropping the values.


#customer_name <-
c("a","NA","c","d","NA","f","g","h","NA","j","k","NA","m","n","o","NA","q","r
","s","NA")
#Electricity_bill <-
data.frame(connection_no,customer_name,village,month,week1,week2,week3,week4,
year,total_units,bill_amount)
#Electricity_bill

#Electricity_bill %>% drop_na(customer_name)

#Q10) Using the replace function.


#Electricity_bill %>% replace_na(list(customer_name='zzz'))

You might also like