Ashies

R

Jan 11th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. # Assign a value to the variables my_apples and my_oranges
  2. my_apples <- 5
  3. my_oranges = 6
  4.  
  5.  
  6. # Add these two variables together and print the result
  7. my_oranges + my_apples
  8.  
  9. # Create the variable my_fruit
  10. my_fruit = my_oranges + my_apples
  11.  
  12.  
  13.  
  14.  
  15.  
  16. # Clear the entire workspace
  17. rm(list = ls())
  18.  
  19. # List the contents of your workspace
  20.  
  21. ls()
  22.  
  23. # Create the variable horses
  24. horses <-3
  25.  
  26.  
  27. # Create the variable dogs
  28. dogs <-7
  29.  
  30.  
  31. # Create the variable animals
  32. animals <- horses + dogs
  33.  
  34.  
  35. # Inspect the contents of the workspace again
  36. ls()
  37.  
  38. # Remove dogs from the workspace
  39. rm(dogs)
  40.  
  41. # Inspect the objects in your workspace once more
  42. ls()
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. # Create variables var1, var2 and var3
  55. var1 <- TRUE
  56. var2 <- 0.3
  57. var3 <- "i"
  58.  
  59. # Convert var1 to a character: var1_char
  60. var1_char <- as.character(var1)
  61.  
  62. # See whether var1_char is a character
  63. is.character(var1_char)
  64.  
  65. # Convert var2 to a logical: var2_log
  66. var2_log <- as.logical(var2)
  67.  
  68. # Inspect the class of var2_log
  69. class(var2_log)
  70.  
  71. # Coerce var3 to a numeric: var3_num
  72. var3_num <- as.numeric("i")
  73.  
  74.  
  75.  
  76. VECTORS
  77.  
  78. numeric_vector <- c(1, 10, 49)
  79. character_vector <- c("a", "b", "c")
  80.  
  81. # Create boolean_vector
  82. boolean_vector <-c(TRUE,FALSE,TRUE)
  83.  
  84.  
  85. # Poker winnings from Monday to Friday
  86. poker_vector <- c(140, -50, 20, -120, 240)
  87.  
  88. # Roulette winnings from Monday to Friday: roulette_vector
  89. roulette_vector <-c(-24,-50,100,-350,10)
  90.  
  91.  
  92. # Poker winnings from Monday to Friday
  93. poker_vector <- c(140, -50, 20, -120, 240)
  94.  
  95. # Roulette winnings from Monday to Friday
  96. roulette_vector <- c(-24, -50, 100, -350, 10)
  97.  
  98. # Add names to both poker_vector and roulette_vector
  99. names(poker_vector) <-c("Monday","Tuesday","Wednesday","Thursday","Friday")
  100. names(roulette_vector) <-c("Monday","Tuesday","Wednesday","Thursday","Friday")
  101.  
  102. # Poker winnings from Monday to Friday
  103. poker_vector <- c(140, -50, 20, -120, 240)
  104.  
  105. # Roulette winnings from Monday to Friday
  106. roulette_vector <- c(-24, -50, 100, -350, 10)
  107.  
  108. # Create the variable days_vector
  109. days_vector <-c("Monday","Tuesday","Wednesday","Thursday","Friday")
  110.  
  111. # Assign the names of the day to roulette_vector and poker_vector
  112. names(poker_vector)<-days_vector
  113. names(roulette_vector)<-days_vector
Add Comment
Please, Sign In to add comment