# This is remarks section
# One can create section heading by ====
# One can create section heading by ----
# One can create section heading by #####
pressing escape - takes you back to prompt
#Step1 first code ====
getwd() # GET Working Directory
setwd() # SET Working Directory (dont forget to add value)
dir() # will show the files in the current directory
list.files() # will shoe the files in the current directory
list.dirs() # will show the directory in the current directory
list.dirs("..") # will shoe the directory of parent directory
?dir # ? followed by the command with open a help file in the help tab
list.files("..") # will show the one directory up files
list.files("../..") # will show the two directry up files
list.files(pattern =".text") # will show all files with .txt extenstion
file.create("a.R") # create a file in local directory
file.info("a.R") # will show file info, with creation, access, modify information
file.copy("a.R", "b.R") # will copy a to b
file.show("a.R") # will show the content on the file console - it can also open the excel file if you want to
file.show("cloud1.png") # will open the photo and show it the screen
file.show("students.csv") # will open the csv file in excel
file.exists("a.R") # if it exist it will return TRUE
file.rename("a.R", "b.R") # to rename a file
file.remove("a.R") # will remove file a.R
unlink("b.R") # will remove file b.R
dir.create("aloo") # will create aloo
unlink("aloo", recursive = TRUE) # delete a folder - Recursive =TRUE is must
**********************
library(tools) # if we load tools library - we can use file_ext command to check extn. of a file
file_ext("a.R") # will show the extentsion of a file
*************************
#Ctrl + L # clear console
#Ctrl + Q # quit R
quit() # to quir R
history() # will show the command line history (512 lines max)
history(10) # will show the last 10 command history
#Step2 ----
?reserved # the words which are already used in R
a <- 10 #to store value in a
b = 5 # will also set b's value to 5 but better to use the assign <-
#Step3 ####
#Use - or = or # 4 times to create sections
b <- 20
c <- a+b
print(c) #normal printing
c #another way to print
class(a) #check type/class of variable
d <- "Swapan"
class(d)
e <- "100"
class(e)
f <- as.numeric(e) #can be used e <- as.something(e)
class(f)
f <- as.character(f)
class(f)
g <- as.numeric(d) #any non numeric stuff in d, g becomes null
g
class(g)
10 -> h #
rm(h) #remove the object
h <- 2 == 3
class(h)
i <- c(10,20,30,40) #similar to array; 1 to n instead of 0 to n-1
class(i)
j <- a*i #multiplies a with all elements of i
k <- a+i[3]
l <- c("Male","Male","Female","Male","Female")
class(l)
m <- as.factor(l)
m
levels(m)
class(m)
try <- i*j #element to element multiplication, not matrix
try2 <- c(1,2,3)
try <- i*try2 #element to element upto smaller max index, then copy
score <- c(40,45,48,38)
stu <- c("Mudit","Rachit","Suraj","Rohan")
class(score)
class(stu)
students <- data.frame(stu,score) #create data frame/table
class(students)
names(students) #column names
students[1] #return first column
students[1,] #return first row
students[,1] #return first column
View(students)
students[3,2]
names(students)[1]
names(students)[1] <- "name" #change column names
students
names(students)[2] <- "marks"
students
a1 <- c("student_name","student_score")
a1
names(students) <- a1
data1 <- read.csv("students.csv") #load csv file onto data1
View(data1)
length(data1$Name) #number of records
head(data1)
tail(data1)
write.csv(data1, file="test.csv") # write the data in onto a new csv file which will have an extra column with row numbers
write.csv(data1, file="test.csv", row.names=False) #without row numbers
ls() #list of loaded variables
search() # shows all packages currently loaded
rm(list=ls()) #removes everything loaded