官术网_书友最值得收藏!

Activity: Creating Vectors, Lists, Matrices, and Dataframes

Scenario

You have been asked to create vectors, lists, matrices, and dataframes that store information about yourself. The expected output is as follows:

Aim

To create vectors, lists, matrices, and dataframes.

Prerequisites

Make sure that you have R and RStudio installed on your machine.

Steps for Completion

  1. Open a new R script and save it as a file called lesson1_activityB2.R.

  2. Create vectors for the following: 

    • The numbers 1:10

    • The letters A:Z, with the first four numbers and letters alternating

Hint: type ?LETTERS into your console.
  1. Create lists for the following:
    • The numbers 1:10
    • The letters A:Z
    • A list of lists:
      • Your favorite foods (two or more)
      • Your favorite TV shows (three or more)
      • Things you like to do (four or more)
  2. Create matrices of numbers and letters by using the following steps:
    1. First, try using cbind() to combine the vector 1:10 and the vector A:Z. What happens?
    2. Figure out a way to combine these two into a matrix, albeit one that will be coerced to character type (despite the numeric column).
  3. Create dataframes using the following steps:
    1. Coerce your matrix solution from the previous second bullet point into a dataframe. View it and take note of the type of each variable.
    2. Use rbind.data.frame() to build a data frame where the rows increase by five until 25, for example, 5, 10, 15, 20, 25.
    3. View it and notice how ugly the column names are. Give it better names ("one" through "five") with the names() function.
主站蜘蛛池模板: 乐东| 林周县| 唐海县| 温州市| 荆门市| 稷山县| 贞丰县| 扎囊县| 紫金县| 厦门市| 布尔津县| 和平县| 和平区| 临洮县| 鹤山市| 县级市| 吉木乃县| 扶余县| 攀枝花市| 万年县| 丁青县| 闵行区| 潜江市| 班玛县| 静海县| 玉门市| 闽侯县| 东乌| 宝坻区| 阳原县| 河曲县| 宕昌县| 元阳县| 贵定县| 祁东县| 鲁山县| 德化县| 陈巴尔虎旗| 义马市| 东阳市| 安福县|