12  Display R code

DRAFT This is a watermark
# logical
c(TRUE, FALSE)
[1]  TRUE FALSE
# integer
0:1
[1] 0 1
# numeric
c(0.0, 1.1)
[1] 0.0 1.1
# scientific
c(1e-10, 1e10)
[1] 1e-10 1e+10
# character
c("Monday", "Tuesday", "Wednesday")
[1] "Monday"    "Tuesday"   "Wednesday"
# factor
factor(c("Monday", "Tuesday", "Wednesday"))
[1] Monday    Tuesday   Wednesday
Levels: Monday Tuesday Wednesday
# function
my_fun <- function(x){
  cat("my function is", x)
}
# data.frame
state <- data.frame(
  region = state.region,
  Division = state.division,
  state.x77
)
# function
my_fun(x = "cool")
my function is cool
# messages
message("this is a message")
this is a message
warning("this is a warning")
Warning: this is a warning
stop("this is an error message")
Error: this is an error message
# programma flow
if (is.data.frame(state)) {
  summary(state)
} else {
  stop("state is not a data.frame")
}
           region                 Division    Population        Income    
 Northeast    : 9   South Atlantic    : 8   Min.   :  365   Min.   :3098  
 South        :16   Mountain          : 8   1st Qu.: 1080   1st Qu.:3993  
 North Central:12   West North Central: 7   Median : 2838   Median :4519  
 West         :13   New England       : 6   Mean   : 4246   Mean   :4436  
                    East North Central: 5   3rd Qu.: 4968   3rd Qu.:4814  
                    Pacific           : 5   Max.   :21198   Max.   :6315  
                    (Other)           :11                                 
   Illiteracy       Life.Exp         Murder          HS.Grad     
 Min.   :0.500   Min.   :67.96   Min.   : 1.400   Min.   :37.80  
 1st Qu.:0.625   1st Qu.:70.12   1st Qu.: 4.350   1st Qu.:48.05  
 Median :0.950   Median :70.67   Median : 6.850   Median :53.25  
 Mean   :1.170   Mean   :70.88   Mean   : 7.378   Mean   :53.11  
 3rd Qu.:1.575   3rd Qu.:71.89   3rd Qu.:10.675   3rd Qu.:59.15  
 Max.   :2.800   Max.   :73.60   Max.   :15.100   Max.   :67.30  
                                                                 
     Frost             Area       
 Min.   :  0.00   Min.   :  1049  
 1st Qu.: 66.25   1st Qu.: 36985  
 Median :114.50   Median : 54277  
 Mean   :104.46   Mean   : 70736  
 3rd Qu.:139.75   3rd Qu.: 81162  
 Max.   :188.00   Max.   :566432  
                                  
for (i in 1:5) {
  cat("i =", i, "\n")
}
i = 1 
i = 2 
i = 3 
i = 4 
i = 5 

Creative Commons-License Test, G. et al. (9999) !!! Missing flandersqmd.doi !!!