In this R markdown document, you should answer each question and click the knit button to generate a pdf or HTML or word document, which should be submitted into D2L.

Type answers after the -> sign.

The ChickWeight data frame has 578 rows and 4 columns from an experiment on the effect of diet on early growth of chicks. The body weights of the chicks were measured at birth and every second day thereafter until day 20. They were also measured on day 21. There were four groups on chicks on different protein diets.

library(datasets)
data("ChickWeight")
str(ChickWeight)
## Classes 'nfnGroupedData', 'nfGroupedData', 'groupedData' and 'data.frame':   578 obs. of  4 variables:
##  $ weight: num  42 51 59 64 76 93 106 125 149 171 ...
##  $ Time  : num  0 2 4 6 8 10 12 14 16 18 ...
##  $ Chick : Ord.factor w/ 50 levels "18"<"16"<"15"<..: 15 15 15 15 15 15 15 15 15 15 ...
##  $ Diet  : Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ...
##  - attr(*, "formula")=Class 'formula'  language weight ~ Time | Chick
##   .. ..- attr(*, ".Environment")=<environment: R_EmptyEnv> 
##  - attr(*, "outer")=Class 'formula'  language ~Diet
##   .. ..- attr(*, ".Environment")=<environment: R_EmptyEnv> 
##  - attr(*, "labels")=List of 2
##   ..$ x: chr "Time"
##   ..$ y: chr "Body weight"
##  - attr(*, "units")=List of 2
##   ..$ x: chr "(days)"
##   ..$ y: chr "(gm)"
  1. What type of variable is Diet?

-> Factor (nominal)

  1. What type of variable is Time?

-> Factor (continuous)

  1. What type of variable is Chick?

-> ord. factor (ordinal)

  1. What type of variable is weight?

-> Num (continuous)

#Get help from R and find information about Data
?ChickWeight
  1. Paste the description below from help.

-> The ChickWeight data frame has 578 rows and 4 columns from an experiment on the effect of diet on early growth of chicks

names(ChickWeight)
## [1] "weight" "Time"   "Chick"  "Diet"
  1. What are the names for from the function names()?

-> names of variables

dim(ChickWeight) # dimension of dataset
## [1] 578   4
nrow(ChickWeight) # number of rows
## [1] 578
ncol(ChickWeight) # number of columns
## [1] 4
  1. What is the sample size of dataset?

-> 578

  1. How many variables in the dataset?

-> 4

subchick <- ChickWeight[, c("weight", "Chick")] # subsetting the original dataset
  1. What is the name of the new dataset?

-> subchick

  1. How many variables are in the new dataset? What are they?

-> 2 variable: “weight” and “chick”

Import dataset stored in local directory

Now, we practice how to import data from various file types in into R.

First, write the dataset to your local computer hard disk by update the directory path: /ChickWeight.csv to your own computer path. Here is the function to get the working directory if you want to use your currect working directory:

getwd()
## [1] "/Users/caliplayer/Downloads"
#COPY THE OUTPUT FROM THE CHUNK WITH getwd() AND PASTE IT BETWEEN "/ IN THE CODE BELOW
write.csv(ChickWeight, "/Users/caliplayer/Downloads/ChickWeight.csv", row.names = FALSE)

To read this data into R, we would use the read.csv() function. Please update the directory path: “/ChickWeight.csv” to your own computer path.

#COPY THE OUTPUT FROM THE CHUNK WITH getwd() AND PASTE IT BETWEEN "/ IN THE CODE BELOW
ChickWeight_data_from_csv = read.csv("/Users/caliplayer/Downloads/ChickWeight.csv")

Now you can use the function head() and other functions we introduced as above to explore the basic features of the imported dataset: ChickWeight_data_from_csv.

head(ChickWeight_data_from_csv, n = 10)
  1. Paste the first 10 observations from your imported data.

->weight Time Chick Diet 1 42 0 1 1 2 51 2 1 1 3 59 4 1 1 4 64 6 1 1 5 76 8 1 1 6 93 10 1 1 7 106 12 1 1 8 125 14 1 1 9 149 16 1 1 10 171 18 1 1

Change the author name in the YAML to your name, save your file, knit it as an PDF or HTML or word document, change the knitted document’s name to ‘Filename_yourname’ and then submit it to the D2L assignment folder.