#This is comment #Multiple line comment #Contant Declaration C1 = 123; #Output of the constant print(C1); #Read the Variable #Output or print on the screen the Variable print(V1); V2 <- readline("Enter the number : "); print(V2) #Take input with a prompt v3 <- readline("Please Enter You Name : "); print(v3) #Take input with a prompt v4 <- readline("Please Enter You Name : "); print("Your name is : ") print(v4) arr1 <- c(1,2,3,4,5,6) print(class(arr1)) print(arr1) print(arr1[1]); print(arr1[2]); arr2 <- c('IIM','IIT','NIT','VIT','BITS') print(arr2) arr2[2] <- "BHU" print(arr2) # The first attributes is a numeric vector # containing the employee IDs which is created # using the command here empId = c(1, 2, 3, 4) # The second attribute is the employee name # which is created using this line of code here # which is the character vector empName = c("Debi", "Sandeep", "Subham", "Shiba") # The third attribute is the number of employees # which is a single numeric variable. numberOfEmp = 4 # We can combine all these three different # data types into a list # containing the details of employees # which can be done using a list command empList = list("John", "Akshay", "Virat") print(empList) empList[[2]][1] <- "Rajiv" print(class(empList))#Function Class() is used to tel the data type print(empList) # declare boolean x <- TRUE print(x) print(class(x)) # declare boolean using single character y <- F print(y) print(class(y)) var1 <- "Rohit" print(class(var1)) var2 <- 12345 print(class(var2)) # concatenation example # create two strings string1 = "Hello" string2 = "World" # concatenate two strings result = paste(string1, string2 ) print(result) # create two strings string1 = "Hello" string2 = "World" # concatenate two strings using separator result = paste(string1, string2, sep = "-" ) print(result) #Substitution Examples # the input vector # the input vector df<-"R is an open-source programming language widely used for data analysis and statistical computing." # the replacement sub('R','The R language',df) #Substitution Examples # the input vector # the input vector df1<-"R is an open-source programming language, R is widely used for data analysis and statistical computing." # the replacement sub('R','The R language',df1) # the replacement gsub('R','The R language',df1) #Count Characters # creating a string mystring <- "HelloWorld!" # using the nchar() function nchar(mystring) #Take 2 numbers and compare num1 <- 150; num2 <- 100; if (num1 < num2) { print("True") } #Input a number x <- readline("Enter the age : "); print(paste(x, " is the age given")); if (x < 18) { print("Person is a minor"); }else if (x > 18){ print("Person is a major"); } #Nested Ifs with "and" condition x <- readline("Enter the age : "); if (x > 18) { if (x >= 20 & x < 30) { print("Person is in his 20s") } if (x >= 30 & x < 40) { print("Person is in his 30s") } if (x >= 40 & x < 50) { print("Person is in his 40s") } if (x >= 50 & x < 60) { print("Person is in his 50s") } if (x >= 60 & x < 70) { print("Person is in his 60s") } if (x >= 70 & x < 80) { print("Person is in his 70s") } if (x >= 80 & x < 90) { print("Person is in his 80s") } if (x >= 90 & x < 100) { print("Person is in his 90s") } }else if (x < 18){ print("Person is a minor") } #OR example a <- 66 b <- 33 c <- 500 if (a > b | a > c) { print("At least one of the conditions is true"); } else {print("Condition not satisfied")} #Loops Example #for loop #Numeric num1 <- readline("Enter a number : "); for (i in 1:num1) { print(i); } #Character/String strarray <- letters[1:26] for (i in strarray ) { print(i); } #While Loop var1 <- 0; while (var1 <= 10) { print(var1) var1 <- var1 + 1 } #While Loop with break var1 <- 0; while (var1 <= 10) { print(var1) var1 <- var1 + 1 if (var1 == 5) { break; } } #Algorithm ---------------Dont compile Read the records in the file() In case of any data descripency the error needs to be raised # pseudo code---------------Dont compile while (record in file) { store filerecord in table record <- record +1 if (column1 is null) {raise exception or write error in logtable; break } } }