diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/lesson2/What_is_a_RMD_file.Rmd b/lesson2/What_is_a_RMD_file.Rmd index 9b9e44f..43a968e 100644 --- a/lesson2/What_is_a_RMD_file.Rmd +++ b/lesson2/What_is_a_RMD_file.Rmd @@ -1,9 +1,16 @@ -Title +Speed and Stopping Distances of Cars ======================================================== This is an R Markdown document or RMD. Markdown is a simple formatting syntax for authoring web pages (click the **Help** toolbar button for more details on using R Markdown). +```{r} +?cars +str(cars) +``` +```{r fig.width=7, fig.height=6} +plot(cars) +``` diff --git a/lesson2/demystifying.R b/lesson2/demystifying.R index 3e5b4fe..205349f 100644 --- a/lesson2/demystifying.R +++ b/lesson2/demystifying.R @@ -55,7 +55,7 @@ numbers udacious <- c("Chris Saden", "Lauren Castellano", "Sarah Spikes","Dean Eckles", "Andy Brown", "Moira Burke", - "Kunal Chawla", YOUR_NAME) + "Kunal Chawla", "Dustin Pianalto") # Notice how R updates 'udacious' in the workspace. # It should now say something like 'chr[1:8]'. diff --git a/lesson2/demystifyingR2.Rmd b/lesson2/demystifyingR2.Rmd index ea9e92c..c097374 100644 --- a/lesson2/demystifyingR2.Rmd +++ b/lesson2/demystifyingR2.Rmd @@ -24,13 +24,14 @@ Subset the data so that you create a new data frame that contains cars that get 23 or more mpg (miles per gallon). Save it to a new data frame called efficient. ```{r} - +efficient <- mtcars[mtcars$mpg >= 23,] +efficient ``` 3. How many cars get more than 23 mpg? Use one of the commands you learned in the demystifying.R to answer this question. ```{r} - +dim(efficient) ``` 4. We can also use logical operators to find out which car(s) get greater @@ -66,13 +67,15 @@ Now you try some. 6. Print the cars that have a 1/4 mile time (qsec) less than or equal to 16.90 seconds to the console. ```{r} - +mtcars[mtcars$qsec <= 16.90,] ``` 7. Save the subset of cars that weigh under 2000 pounds (weight is measured in lb/1000) to a variable called lightCars. Print the numbers of cars and the subset to the console. ```{r} - +lightCars <- mtcars[mtcars$wt <= 2.0,] +dim(lightCars) +lightCars ``` 8. You can also create new variables in a data frame. Let's say you wanted @@ -104,7 +107,7 @@ Open the table of values to see what values year takes on. Drop the year variable from the data set. ```{r} - +mtcars <- subset(mtcars, select = -year) ``` @@ -164,6 +167,10 @@ answer a question to continue on in Lesson 2. Which car(s) have an mpg (miles per gallon) greater than or equal to 30 OR hp (horsepower) less than 60? Create an R chunk of code to answer the question. +```{r} +answer = mtcars[mtcars$mpg >= 30 | mtcars$hp < 60,] +answer +``` Once you have the answer, go the [Udacity website](https://www.udacity.com/course/viewer#!/c-ud651/l-729069797/e-804129319/m-811719066) to continue with Lesson 2. diff --git a/lesson2/lesson2.Rproj b/lesson2/lesson2.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/lesson2/lesson2.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/lesson2/reddit_graphs.R b/lesson2/reddit_graphs.R new file mode 100644 index 0000000..bb53bcc --- /dev/null +++ b/lesson2/reddit_graphs.R @@ -0,0 +1,10 @@ +reddit <- read.csv('reddit.csv') + +table(reddit$employment.status) +summary(reddit) + +library(ggplot2) +age.ordered <- ordered(reddit$age.range, levels = c('Under 18', '18-24', '25-34', '45-54', '55-64', '65 or Above', 'NA')) +qplot(data = reddit, x = age.ordered) +qplot(data=reddit, x=income.range) +