#packages----
installed.packages()
search() #no. of libraries loaded on the system
install.packages("tidyverse") #install a particular package
install.packages("pacman")
search() #list of active libraries
library("pacman") #load a particular package(can't load multiple packages at the same time)
p_load(tidyverse) #using pacman to load tidyverse(can load multiple packages at the same time using pacman)
library(help="tidyverse") #more info on that library
p_loaded(tidyverse) #check whether a library loaded or not
library(help="pacman")
p_library() #list of libraries installed
p_isinstalled(XML) #check whther a particular package is installed or not
#u need to load all(needed) libraries again whenever u restart RStudio
p_isinstalled(readxl)
p_load(readxl)
search()
install.packages("openxlsx")
detach(package:readxl) #unload a package from environment
p_load(readxl,openxlsx)
p_unload(all) #unload all packages
pacman::p_load(tidyverse,pacman) #use a function from a library which is not loaded
remove.packages("openxlsx") #uninstalling & not unloading
#at the very end ----
p_unload(all) #remove all libraries
rm(list=ls()) #remove all objects
q() #quit
#playing around with strings----
pacman::p_load(tidyverse,pacman)
d1<-"Swapan Purkait"
d2<-str_to_upper(d1) #all uppercase
d3<-str_to_lower(d1) #all lowercase
d4<-str_to_title(d3) #1st letter of words capital
d5<-" Dhruvit is a good boy "
d5
d6<-str_trim(d5) #removes spaces only from start & end of the string
d6
d7<-str_squish(d6) #manages spaces to form a proper sentence
d7
d8<-str_sub(d1,1,6) #takes up the part of the string from char nos. in last 2 arguments
d8
d9<-str_replace(d1,pattern = "Purkait",replacement = "Superman") #replace all Purkait s with Superman in the string
d9
#start playing with dataframes---
data<-read.csv("stu.csv")
class(data)
data1<-data
data<-as.tibble(data)
class(data)
class(data1)
data
data1
glimpse(data)
glimpse(data1)
head(data)
head(data1)
names(data)
names(data)<-str_to_lower(names(data)) #all headings in lower case
n1<-c("sr","name","email","id","phone")
names(data)<-n1
View(data)
data2<-select(data,-email) #removes the column email
view(data2)
data3<-select(data,id,name,phone,email) #rearranges the columns in the order mentioned
view(data3)
data%>%filter(name=="Harsh Jain")%>%print() # %>% is called piping #it prints the whole row of data with exact entry 'Harsh Jain' in name column
data%>%filter(grepl("ph",name))%>%print() # print all rows having 'ph' somewhere in the entries in name column
data%>%filter(grepl("h",email))%>%print()
data%>%filter(grepl("h",email))->hemail #creates a file hemail with only those rows who have 'h' somewhere in the entries in email column
View(hemail)
data%>%filter(name=="Harsh Jain" | name=="Dhruvit Jhaveri")%>%print() #same as 40 but for multiple arguments
write.csv(hemail,file = "hemail.csv",row.names = FALSE)
file.show("hemail.csv")
#this is where we end----
p_unload(all)
rm(list = ls())
q()