Assigning Operator

it will srore a value in a variable

x<-c(1,2,3)

a<-2 a

Function charaterstics

Function C to comine num

x<-c(5:10)

Extention Package

x<-c(1,2,3)

Function , comment ,Install packages

x<-c(1:20)
x
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
>install packages("ggplot2")

this
there
are

how to call documents

x<-c(1,2,3,4:10,NA)
help(sd)
## starting httpd help server ... done
args(sd)
## function (x, na.rm = FALSE) 
## NULL
example(sd)
## 
## sd> sd(1:2) ^ 2
## [1] 0.5

assignemt

create vector

 x<-c(4,7,3,2,8)
x
## [1] 4 7 3 2 8
y<-x+2
y
## [1]  6  9  5  4 10
mean(y)
## [1] 6.8
sd(y)
## [1] 2.588436
z<-c(2,3)
z
## [1] 2 3
e<-x+z
## Warning in x + z: longer object length is not a multiple of shorter object
## length
e
## [1]  6 10  5  5 10

character numaric interaction logical complex

R Attributes names dimension class length

creating vector

missing object

y<-c(1.7,"a")

numaric and integer Explicit coretion

matrices coloum bind row bind function

assignement

create a /list whose first element is 2-element set of names say “atanu”and“karam”,second elements is aset of numers like 2,3,5,19,2,7,5,5. check the class of second element of the list. print the 4th element of the 2nd element of the list. change the 1st element of the list as factor. find out the frequncy of each element of the 2nd element of the list

assign<-list(c("Atanu","Karam"),c(2,3,5,19,2,7,5,5))


class(assign[[2]])
## [1] "numeric"
assign[[c(2,4)]]
## [1] 19
as.factor(assign [[1]])
## [1] Atanu Karam
## Levels: Atanu Karam
x<-c(1,2,3,NA,3,NaN)

Exam..

```r

1)create one 5-d vector of values 4,7,3,2,5

 x<-c(4,7,3,2,5)
 x
## [1] 4 7 3 2 5

2)add 2 to x..assigns the value to y

y<-x+2

y
## [1] 6 9 5 4 7

3)Find the mean sd of y

mean(y)
## [1] 6.2
sd(y)
## [1] 1.923538

4)create whether variable z as combination of 2,3.

z<-c(2,3)
z
## [1] 2 3

5)Add x and z ```

x+z
## Warning in x + z: longer object length is not a multiple of shorter object
## length
## [1]  6 10  5  5  7

—-atomic character numeric(real numbers) integer complex logical(T/F)

class

x<-1
class(x)            # shows data type
## [1] "numeric"
x<-1L
class(x)
## [1] "integer"
class(x)
## [1] "integer"
x<-as.character  
class(x)
## [1] "function"
1/0
## [1] Inf

Creating Vector

x<- c(0.5,0.6)

x<-c(TRUE,FALSE)

x<-9:23

Attributes

:(sequence operaor)

x<-c(1:20)
length(x)
## [1] 20
x<-c(1:20,"karam")
length(x)
## [1] 21

Evaluation

print(x)
##  [1] "1"     "2"     "3"     "4"     "5"     "6"     "7"     "8"    
##  [9] "9"     "10"    "11"    "12"    "13"    "14"    "15"    "16"   
## [17] "17"    "18"    "19"    "20"    "karam"
x<-c(0.1)

Matrix

m<- matrix(1:20,nrow=2)
s<-matrix(1:20,2,byrow = T)
dim(s)
## [1]  2 10
x<-1:10
dim(x)=c(2,5)

Cbing & rbing

x<-1:6
y<-5:10

cbind(x,y)           # coulmn binding
##      x  y
## [1,] 1  5
## [2,] 2  6
## [3,] 3  7
## [4,] 4  8
## [5,] 5  9
## [6,] 6 10
rbind(x,y)           # row binding
##   [,1] [,2] [,3] [,4] [,5] [,6]
## x    1    2    3    4    5    6
## y    5    6    7    8    9   10

List

x<-list(c(1,2,3),c("jagadish","karam"))    

x
## [[1]]
## [1] 1 2 3
## 
## [[2]]
## [1] "jagadish" "karam"
x[[c(1,2)]]
## [1] 2
x[[c(2,1)]]
## [1] "jagadish"

Factor

x<-factor(c("yes","yes","no","yes"))
x
## [1] yes yes no  yes
## Levels: no yes
class(x)
## [1] "factor"
y<- factor(x,exclude=NA)

table(x)
## x
##  no yes 
##   1   3
unclass(x)
## [1] 2 2 1 2
## attr(,"levels")
## [1] "no"  "yes"

..Exam


1) create a list whose first element is 2-element set of names say "Atanu", and "Karam"
, second element is a set of numbers like 2,3,5,19,2,7,5,5.
y<-list(a=c("Atanu","Karam"),b=c(2, 3,5,19,2,7,5,5) )
y
## $a
## [1] "Atanu" "Karam"
## 
## $b
## [1]  2  3  5 19  2  7  5  5
2)Check the class of second elemnt of the list.?
class(y[[c(1,2)]])
## [1] "character"
3) print the 4 th element of the 2nd element of the list.?
y[[c(2,4)]]
## [1] 19
4)change the 1st element of the list as factor.
y<- as.factor (y[[1]])
 y
## [1] Atanu Karam
## Levels: Atanu Karam

5)find out the frequency of each element of the 2nd element of the list.?

y[[c(2)]]
## [1] Karam
## Levels: Atanu Karam

Missing values: NA,NAN, blankspace

x<-c(1,2,3,4,NA,1,NaN)
x
## [1]   1   2   3   4  NA   1 NaN
is.na(x)    # checking NA is there r not
## [1] FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE
is.nan(x)   #checking NaN is there r not
## [1] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE

import coloums 5&7

wine<-read.csv("C://jagadeesh")
View(wine)
colnames(Wine)<-c("Alcohol","Malic acid","Ash","Alcalinity of ash"," Magnesium","Total phenols","Flavanoids",                            "Nonflavanoid phenols","Proanthocyanins","Color intensity","Hue","OD280/OD315 of diluted",                             "wines")

``` col(iris) < - C(“sepal length in cm”,“sepal width in cm”, “petal length in cm”,“petal width in cm”,“Species”)

iris=subset(iris)

adult rename coloum

```r adult <- read.csv(“C:\Users\LOCALA~1\AppData\Local\Temp\RtmpmShtIW\data16581ca66a9b”, header=FALSE) View(adult) names(adult)<-c(“age”,“workclass”,“fnlwgt”, “education”,“educationnum”,“maritalstatus”, “occupation”,“relationship”,“race”,“sex”, “capitalgain”,“capitalloss”,“hoursperweek”, “nativecountry”,“Income”)

View(adult)

plot(cars) grid() lines(cars)

paired observation

View(iris)

with(iris,plot(Petal.Length,Petal.Width,pch=as.integer(Species)))
f<-factor(iris$species)
legend(1.5,2.4,as.character(levels(f)),pch=1:length(levels(f)))
location<-c("AS","we","ER","QW")
treatment<-c("T1","T2","T3","T4")
outer(location,treatment,paste,sep=",")    ## adding to rows
##      [,1]    [,2]    [,3]    [,4]   
## [1,] "AS,T1" "AS,T2" "AS,T3" "AS,T4"
## [2,] "we,T1" "we,T2" "we,T3" "we,T4"
## [3,] "ER,T1" "ER,T2" "ER,T3" "ER,T4"
## [4,] "QW,T1" "QW,T2" "QW,T3" "QW,T4"
treatment<-c("1","2","3","4")
outer(location,treatment,paste,sep=",")
##      [,1]   [,2]   [,3]   [,4]  
## [1,] "AS,1" "AS,2" "AS,3" "AS,4"
## [2,] "we,1" "we,2" "we,3" "we,4"
## [3,] "ER,1" "ER,2" "ER,3" "ER,4"
## [4,] "QW,1" "QW,2" "QW,3" "QW,4"
paste("sujith","sssss","eeeeee",sep=" ") ## combining with space
## [1] "sujith sssss eeeeee"
Sys.Date()
## [1] "2015-10-07"
class(Sys.Date())
## [1] "Date"
m<-"2015/10/06"
class(m)
## [1] "character"
date2<-as.Date(m,format="%Y/%m/%d")
class(date2)
## [1] "Date"
ISOdate(2015,8,06)    ## change the date
## [1] "2015-08-06 12:00:00 GMT"
as.Date(ISOdate(2015,8,06))     ## convert chart to date
## [1] "2015-08-06"
class(as.Date(ISOdate(2015,8,06)))
## [1] "Date"
w<-as.Date(ISOdate(2015,8,06))    
format(w,"%Y")
## [1] "2015"
class(format(w,"%Y"))
## [1] "character"
as.integer(format(w,"%Y"))
## [1] 2015
data() ## all dataset in R
View(cars)
plot(cars$speed,cars$dist)

plot(cars,main="scatterplot",xlab="speed",ylab="dist")
grid()         ## gives lines inside the plot

lines(cars)  ## gives line to the points

with(iris,plot(Petal.Length,Petal.Width,pch=as.integer(Species)))

pairs(iris) ## gives all 
f<- factor(iris$Species)
legend(1.5,2.4,as.character(levels(f)),pch=1:length(levels(f)))

coplot

data(Cars93,package="MASS")
library(MASS)
View(Cars93)
coplot(Horsepower ~ MPG.city | Origin,data = Cars93)


k<-list(a=c(1,2,3,5),b=c("jagadeesh","karam","atanu"))