#Clear objects (data) and command history in R/RStudio.
rm(list = ls()) # Clear environment
cat("\014") # Clear console
if (file.exists(".Rhistory")) file.remove(".Rhistory") # Remove history files if present
rh = file.path(path.expand("~"), ".Rhistory")
if (file.exists(rh)) file.remove(rh)
#install packages
options(repos = c(CRAN = "https://cloud.r-project.org"))
install.packages("officedown") #Sets the default CRAN repository (download server) for installing packages in the current R session.
## Installing package into 'C:/Users/PCPV/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
##
## There is a binary version available but the source version is later:
## binary source needs_compilation
## officedown 0.4.0 0.4.1 FALSE
## installing the source package 'officedown'
library(officedown)
library(officer)
#5.8. Install the R package
install.packages("ggplot2") #install ggplot2 and psych packages
## Installing package into 'C:/Users/PCPV/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
##
## There is a binary version available but the source version is later:
## binary source needs_compilation
## ggplot2 3.5.1 4.0.2 FALSE
## installing the source package 'ggplot2'
library (ggplot2) # call ggplots package in R
#Running the basic R commands
#5.1. Arithmetic Operations
log(1000); abs(-3); sqrt(16)
## [1] 6.907755
## [1] 3
## [1] 4
#5.2. Creating Objects (Variables)
x <- 10
y <- 5
A=x + y
A
## [1] 15
#5.3. Working with vectors
WG <- c(2,6,8,10,12)
WG
## [1] 2 6 8 10 12
#5.4. Working with characters
sample <- c("A", "B", "C", "D")
sample
## [1] "A" "B" "C" "D"
#5.5. Working with matrices (tables)
Temperature=c(25,30,35,40)
Rate= c(0.15,0.30,0.55,0.80)
Experiment=data.frame(Temperature, Rate)
Experiment
#5.8. Importing data in R from excel file
data=read.csv("D:/lecture notes/Applied statistics/Applied Stat lab/data/dat1R.csv") # import it into R for data with column names in the first row
head(data) #shows the first 6 rows
tail(data) #shows the last 6 rows
attach(data) # lets R know that this is the data table that we are working with right now