R 고급 데이터 관리

student<-c("John Davis","Angela williams","Bullwinkle Moose","David Jones","Janice Markhammer","Cheryl Cushing","Reuven Ytzrhak","Greg Knox","Joel England","Mary Rayburn")
math<-c(502,600,412,358,495,512,410,625,573,522)
science<-c(95,99,80,82,75,85,80,95,89,86)
english<-c(25,22,18,15,20,28,15,30,27,18)

roster<- data.frame(student,math,science,english,stringAsFactors=FALSE)
z<-scale(roster[,2:4])
z
score <- apply(z,1,mean)
roster<-cbind(roster,score)
y<-quantile(score,c(.8,.6,.4,.2))
roster$grade[score>=y[1]]] <- "A"
roster$grade[score<y[1] & score >=y[2]]] <- "B"
roster$grade[score<y[2] & score >=y[3]]] <- "C"
roster$grade[score<y[3] & score >=y[4]]] <- "D"
roster$grade[score<y[4]]] <- "F"
roster
#       
    #    
        #abs(x)
        #sqrt(x)
        #ceiling(x)  #   x     
        #floor(x)    #   x     
        #trunc(x)    # x     
        #round(x,digits=n)  #     n           
        #signif(x,digits=n) #     n       ,     。
        #cos(x) sin(x) tan(x)        #  、  、  
        #acos(x) asin(x) atan(x)     # (  、  、  )
        #cosh(x)  sinh(x)  tanh(x)   #   (  、  、  )
        #acosh(x) asinh(x) atanh(x)  #    (  、  、  )
        #log(x, base=n)              # x  n     
        #exp(x)
  
    #    
        #mean(x)    #   
        #Median(x)  #   
        #sd(x)      #   
        #var(x)     #  
        #mad(x)     #     
        #quantile(x,probs)  #    
        #range(x)   #   
        #sum(x)     #  
        #diff(x,lag=n)  #    
        #min(x)     #    
        #max(x)     #    
        #scale(x,center=TRUE,scale=TRUE)  #   x           

#      
    #beta        beta
    #         binom
    #          cauchy
    #          chisq
    #          exp
    #F           f
    #Gamma       gamma
    #          geom
    #         hyper
    #        lnorm
    #Logistic    logis
    #         multinom
    #         nbinom
    #          norm
    #          pois
    #Wilcoxon        signrank
    #t           t
    #          unif
    #Weibull     weibull
    #Wilcoxon        wilcox

#      
    #nchar(x)  #  x      
    #substr(x,start,stop) #    
    #grep(pattern,x,ignore.case=FALSE,fixed=FALSE)  # x       ,
    #sub(pattern,replacement,x,ignore.case=FALSE,fixed=FALSE)
    #strsplit(x,split,fixed=FALSE)  # split    x
    #paste(...,sep="")   #     ,     sep
    #toupper(x)       
    #tolower(x)       

#      
    #lenth(x)
    #seq(from,to,by) #      
    #rep(x,n)  # x  n 
    #cut(x,n)  #      x     n      
    #pretty(x,n) #       ,    n+1        ,        x   n   ,
    #cat(...,file="myfile",append=FALSE)  #   。。。    ,           
x<-pretty(c(-3,3),30)
y<-dnorm(x)
plot(x,y,type="l",xlab="NormalDeviate",ylab="Density",yaxs="i")

#       
    #for
    # for (var in seq) statement
    for (index in 1:10) print (index)
    for (index in c(1,2,3,9)) print (index)

    #while
    # while (condition) statement
      i <- 10
      while (i > 0) 
      {
        print (i)
        i <- i - 1
      }

    
    #  
    if (condition) statment
    if (condition) statment1 else statment2
    ifelse(condition,statement1,statement2)

    #  
    switch(expr,...)
    feelings <-c("sad","afraid")
    for(i in feelings)
      print (
        switch(i,
               happy= "I am glad you are happy",
               afraid = "There is nothing to fear",
               sad = "Cheer up",
               angry = "Calm down now"
               )
        )
    


#    
    #myfuntion <- function(arg1,arg2,...)  #             
    #{
    #  statements
    #  return (object)
    #}




#       
    #   

좋은 웹페이지 즐겨찾기