Escolar Documentos
Profissional Documentos
Cultura Documentos
library(gdata)
Electronic = read.xls("Electronic.xls")
View(Electronic)
getwd()
min(HSB$math)
max(HSB$math)
mean(HSB$math)
# OR
apply(cbind(HSB$math),2,mean)
HSB1 = cbind(HSB,Average_M_S)
View(HSB1)
MeanOfAllSubjects = lapply(HSB[,7:11],mean)
# below will not give desired output. Cbind not to be used in lapply function
lapply(cbind(HSB$read,HSB$write),mean)
class(MeanOfAllSubjects)
NewDataFrame = cbind(HSB$read,HSB$write)
View(NewDataFrame)
# OR
NewDataFrame = HSB[,7:8]
View(NewDataFrame)
## apply: col wise and row wise functions. Define each variable. Class of object is
vector
## lapply: Performs function on all variables by default. Col wise function. Class
is list
## sapply: similar to lapply function with only difference that class is numeric
vector
class(HSB)
is.data.frame(HSB)
# tapply function
tapply(HSB$math,HSB$female,mean)
# where female = 1
library(dplyr) # PENDING DPLYR package
HSBFemaleData = filter(HSB, female == 1)
View(HSBFemaleData)
tapply(HSBFemaleData$math,HSBFemaleData$female,mean)
class(tapply(HSB$math,HSB[,c("female","ses")],mean))
# Below will not work
class(tapply(HSB$math,cbind(HSB$female,HSB$ses),mean))
mtcarsWithGearMilage = mtcars[,c(1,10)]
View(mtcarsWithGearMilage)
# OR
mtcarsWithGearMilage = select(mtcars,gear,mpg)
View(mtcarsWithGearMilage)
View(iris)
irisSubset = select(iris,starts_with("Petal"))
View(irisSubset)
irisSubset = select(iris,ends_with("Width"))
View(irisSubset)
# filter data
View(mtcars)
mtcarsSubset = filter(mtcars, mpg>20)
View(mtcarsSubset)
# AND CONDITION
mtcarsSubset = filter(mtcars, mpg>20 & hp > 100 & gear>3)
View(mtcarsSubset)
# OR condition
mtcarsSubset = filter(mtcars, mpg>20 | hp > 100)
View(mtcarsSubset)