R is a programming language and software environment for statistical analysis, graphics representation and reporting. R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team. This programming language was named R, based on the first letter of first name of the two R authors (Robert Gentleman and Ross Ihaka)
# My first program in R Programming {this is comments}
myString <- "Hello, World!"
print ( myString)
## [1] "Hello, World!"
# My first program in R Programming
you need to use various variables to store various information. Variables are nothing but reserved memory locations to store values. This means that, when you create a variable you reserve some space in memory.
a <- 5
print(a)
## [1] 5
print(class(a))
## [1] "numeric"
b = 6
b
## [1] 6
class(b)
## [1] "numeric"
7->c
c
## [1] 7
class(c)
## [1] "numeric"
# integer
d <- 5L
d
## [1] 5
class(d)
## [1] "integer"
# Character
e = "anoop"
e
## [1] "anoop"
class(e)
## [1] "character"
# Logical
TRUE->f
f
## [1] TRUE
class(f)
## [1] "logical"
a=5
b=5
a+b
## [1] 10
sum(a,b)
## [1] 10
b = 13
a < b
## [1] TRUE
a > b
## [1] FALSE
a == b
## [1] FALSE
a <= b
## [1] TRUE
a >= b
## [1] FALSE
a*b
## [1] 65
a!=b
## [1] TRUE
c = 7
(a < b) & (a < c)
## [1] TRUE
(a < c) | (a < c)
## [1] TRUE
if(a < 10)
{
print(" a is lessthan 10 ")
}else{
print(" a is greater than 10 ")
}
## [1] " a is lessthan 10 "
a
## [1] 5
b
## [1] 13
if( a< b){
print(" a is lessthan b")
}else{
print(" a is greater than b")
}
## [1] " a is lessthan b"
a = 15
if(a<10 & a>0)
{
print("a is less than 10")
print(a)
} else if (a>20)
{
print("a is greater than 20")
print(a)
}else
print("a has a value between 10 and 20")
## [1] "a has a value between 10 and 20"
fn = function(x,y)
{
return(x+y)
}
fn(4,5)
## [1] 9
fn(4,5)->p
p
## [1] 9
b
## [1] 13
print(a, b)#prints the value of a
## [1] 15
paste(2,3)#default seperator is space
## [1] "2 3"
paste(a, b, 5,sep = ",")#the default sep is space
## [1] "15,13,5"
paste(a,b,10,20,100.3,sep = ", ")->var
print(var)
## [1] "15, 13, 10, 20, 100.3"
p=paste(2,3,4,5,6,8, sep = "") #sep = blank to take off the space
print(p)
## [1] "234568"
if(a<10)
print(paste("a is less than 10. The value of a is: ", a, sep = "")) else
print(paste("a is greater than 10. The value of a is: ",a, sep = ""))
## [1] "a is greater than 10. The value of a is: 15"
if(a<10)
cat("a is less than 10. The value of a is: ", a, sep = "") else
cat("a is greater than 10. The value of a is: ",a, sep = "")
## a is greater than 10. The value of a is: 15
cat(a,b)#puts the default sep of " "
## 15 13
cat(a, b, sep = ", ")
## 15, 13
cat(a,b,sep = "")
## 1513
paste(a,b)->c
c->d
d
## [1] "15 13"
print(a)->e
## [1] 15
e
## [1] 15
paste(a,b)->c
print(c)
## [1] "15 13"
cat(a,b)->c #it returns null
## 15 13
c
## NULL
#it's only used for pasting and printing