Section 25 Create Data


  • Set the seed as 12345.

  • Create a character vector ID of length 100 as S1, S2, …, S100

  • Generate a random sample of size 100 from a normal distribution with mean=10, sd=2. Name this vector as Wt. Round the values to two decimal places.

  • Generate random uniform sample of size 100 between 1 to 2. Name this vector as Age. Round the values to two decimal places.

  • Create a character vector of size 100 with first 50 elements as M and the second 50 elements as F. Name this vector as Sex.

  • Create a logical vector of size 100 using random sampling with the probability of being TRUE as 0.60. Name this vector as Vac.

  • Now create a data.frame that includes four columns: Wt, Age, Sex and Vac.

  • Replace the Age of the 10th subject with NA.

  • Replace the Wt of the 20th subject with NA.

  • Explore the created data.frame. Identify data types of each variable (column). Explain the factor variable.