# 4. 2018.02.22 Lesson 5.txt

Description
Categories
Published

View again

4
Categories
Published

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Share
Transcript
# importing excel datalibrary(gdata)Electronic = read.xls( Electronic.xls )View(Electronic)getwd()############## Lesson 5 Apply fnction ############################ ls()View(!)mean(!\$mat%)median(!\$mat%)&antile(!\$mat%)# creating a new 'ariable in dataframeat% = transform(!* mat% = mat%+)View(at%)# ,reate new 'ariable wit% if t%en conditionat% = transform(!* at%-pdated = ifelse(mat%5/*mat%*mat%+))View(at%)at% = transform(!* at%-pdated = ifelse(mat%5/*mat%*5/))View(at%)# complex ifelse conditionat% = transform(!* at%0Le'el = ifelse(mat%1/* ! *ifelse(mat%2/*  * L )))View(at%)min(!\$mat%)max(!\$mat%)at%AndcienceA'erage = transform(!* at%0scince = (mat%+science)34 )View(at%AndcienceA'erage)mean(!\$mat%)# 6apply(cbind(!\$mat%)*4*mean)at%AndcienceA'erage = transform(!* at%0scince = (mat%+science)34 )# 6A'erage00= apply(cbind(!\$mat%*!\$science)**mean)A'erage00View(A'erage00)class(A'erage00)! = cbind(!*A'erage00)View(!)# mat%s and science mean 'erticallyapply(cbind(!\$mat%*!\$science)*4*mean)## lapply fnction7 ,lass is listmean(!\$mat%)mean(!\$science)mean(!\$read)  # 6lapply(!*mean)eanfAllb8ects = lapply(!9*17:*mean)# below will not gi'e desired otpt. ,bind not to be sed in lapply fnctionlapply(cbind(!\$read*!\$write)*mean)class(eanfAllb8ects);ew<atarame = cbind(!\$read*!\$write)View(;ew<atarame)# 6;ew<atarame = !9*17>:View(;ew<atarame)# sapply fnction ? ,lass is nmeric3@nt Vectorm%rog%apply = sapply(!*sm)class(m%rog%apply)is.'ector(m%rog%apply)## apply7 col wise and row wise fnctions. <efine eac% 'ariable. ,lass of ob8ect is'ector## lapply7 Berforms fnction on all 'ariables by defalt. ,ol wise fnction. ,lass is list## sapply7 similar to lapply fnction wit% only difference t%at class is nmeric 'ectorclass(!)is.data.frame(!)# tapply fnctiontapply(!\$mat%*!\$female*mean)# w%ere female = library(dplyr) # BE;<@;C <BLD6 pacage!emale<ata = filter(!* female == )View(!emale<ata)tapply(!emale<ata\$mat%*!emale<ata\$female*mean)### complicated scenerio wit% 4 'ariablestapply(!\$mat%*!9*c( female * ses ):*mean)class(tapply(!\$mat%*!9*c( female * ses ):*mean))# elow will not worclass(tapply(!\$mat%*cbind(!\$female*!\$ses)*mean))### dplyr pacagelibrary(dplyr)# elect few 'ariablesView(mtcars)mtcarsFit%Cearilage = mtcars9*c(*/):View(mtcarsFit%Cearilage)# 6 mtcarsFit%Cearilage = select(mtcars*gear*mpg)  View(mtcarsFit%Cearilage)View(iris)irisbset = select(iris*starts0wit%( Betal ))View(irisbset)irisbset = select(iris*ends0wit%( Fidt% ))View(irisbset)# filter dataView(mtcars)mtcarsbset = filter(mtcars* mpg4/)View(mtcarsbset)# A;< ,;<@@;mtcarsbset = filter(mtcars* mpg4/ G %p  // G gearH)View(mtcarsbset)# 6 conditionmtcarsbset = filter(mtcars* mpg4/ I %p  //)View(mtcarsbset)mtcarsbset = arrange(mtcars* %p)View(mtcarsbset)mtcarsbset = arrange(mtcars* desc(%p))View(mtcarsbset)-E = mtcars9mtcars\$mp4/ G mtcars\$%p //*:View(-E)## transform 's tate fnctionView(!)! = mtate(!* at%s-Bdated = mat% +5* at%s0cience = at%s-Bdated+science)View(!)

Dec 1, 2018

#### 3. 2018.02.21 Lesson 3 &amp; 4.txt

Dec 1, 2018
Search
Similar documents

View more...
Tags

## Mathematical Analysis

Related Search
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x