Advertisement
JustCaused

IS - Skripta 1

Jun 2nd, 2023 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. ###############################
  2. # Vector arithmetics
  3. ###############################
  4.  
  5. # (+, -, *, /, ^)
  6.  
  7. # get the max value
  8.  
  9. # get the min value
  10.  
  11. # get the range of values
  12.  
  13. # calculate the sum of all elements
  14.  
  15. # calculate the product of all elements
  16.  
  17. ################################
  18. # Generating regular sequences
  19. ################################
  20.  
  21. # generate a sequence from 1 to 10
  22.  
  23. # generate a sequence from 10 to 1
  24.  
  25. # generate a sequence from 3.2 to 4.7, with a step 0.2
  26.  
  27. ################################
  28. # Factor values
  29. ################################
  30.  
  31. # create a vector and convert to factor
  32.  
  33. # print unique factor values (levels)
  34.  
  35. # specify the order of level
  36.  
  37. # print the summary
  38.  
  39. ################################
  40. # Missing values
  41. ################################
  42.  
  43. # check which values are NAs
  44.  
  45. # NaN missing value
  46.  
  47. ################################
  48. # Data frame
  49. ################################
  50.  
  51. # create a data frame
  52.  
  53. # create a data frame from existing vectors
  54.  
  55. ################################
  56. # Task 1
  57. ################################
  58.  
  59. # Create a dataframe called *co2.emissions* containing two columns: *years* (2000, 2002, 2004, 2006, 2008, 2010) and *emission* (2.7, 2.9, 4, 4.9, 5.3, 6.2).
  60.  
  61. # Answer:
  62.  
  63. ################################
  64. # Loading data frame from a file
  65. ################################
  66.  
  67. # reading a data frame from the CSV fill
  68.  
  69. # head and tail functions
  70.  
  71. # print the number of rows
  72.  
  73. # print the number of columns
  74.  
  75. # str function
  76.  
  77. # summary function
  78.  
  79. # retrieve and change column names
  80.  
  81. # remove column duration
  82.  
  83. ################################
  84. # Subsetting
  85. ################################
  86.  
  87. # get an element from the row 3, column 1
  88.  
  89. # get the third row
  90.  
  91. # get rows at positions from 3 to 6
  92.  
  93. # get rows at positions 3 and 6
  94.  
  95. # get the second column
  96.  
  97. # get the Year column
  98.  
  99. # retrieve all songs released before year 1965
  100. # alternative
  101.  
  102. # retrieve all songs released before year 1965 with duration lower than 150 seconds
  103. # alternative
  104.  
  105. ################################
  106. # Task 2
  107. ################################
  108. # Print a number of songs from 1963 that last more than 2 minutes (120 seconds).
  109.  
  110. # Answer:
  111.  
  112. ################################
  113. # Plotting
  114. ################################
  115.  
  116. # create a plot for the given vectors
  117.  
  118. # include ggplot2 library
  119.  
  120. # render a plot for the given data frame (columns Year and Duration)
  121.  
  122. # render a scatter plot for Year and Duration
  123.  
  124. # render a scatter plot with custom title and axes labels
  125.  
  126. # render a bar chart displaying the number of songs in each year
  127.  
  128. # improve the previous chart so that only years with songs are shown;
  129. # include title and axes labels
  130.  
  131.  
  132. # render a line chart (Year, Duration) for the first five songs
  133. # with specific line and points properties
  134.  
  135. ################################
  136. # Task 3
  137. ################################
  138.  
  139. # Create a line chart from a dataset *co2.emissions* (created in Task 1) with the x-axis representing the years, and the y-axis representing the values of CO2 emissions.
  140. # Chart title should be "China CO2 Emissions" and y-axis should have a label "CO2 Emissions".
  141.  
  142. # Answer:
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement