Commit 020c82b5 authored by NourElh's avatar NourElh

Update exercice_en.Rmd

parent b43ff87b
...@@ -9,25 +9,48 @@ output: html_document ...@@ -9,25 +9,48 @@ output: html_document
```{r setup, include=FALSE} ```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(echo = TRUE)
``` ```
```{r}
cars=read.csv("./cars.csv",header = T, sep=";")
head(cars)
```
## Some explanations # Data Analysis
## Get the cars having 8 cylinders
This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, see <http://rmarkdown.rstudio.com>. ```{r }
d=cars[cars$cyl==8]
```
When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows:
```{r cars} ## Get the names of the cars having biggest horsepower
summary(cars) ```{r }
d=cars[cars$Horsepower==max(cars$Horsepower)]
names=d['Car']
``` ```
It is also straightforward to include figures. For example:
```{r pressure, echo=FALSE} ## Get all the cars made in Europe
plot(pressure) I don't know how I should write Europe
```{r }
d=cars[cars$Origin=="Europe"]
``` ```
Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible. #Data Visualization
Visualize the evolution of the horsepower according to the numbers of cylinders
```{r }
plot(cars$Cylinders,cars$Horsepower)
```
Visualize the ts of the weight and the acceleration
```{r }
plot.ts(cars$Weight,cars$Acceleration)
```
Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you. Visualize the number of cars produced by origin
I know we can avoid all of this by using ggplot, but I tried to do the group_by using R. However, the "undefined columns selected" error prevents me from visualizing the data.
```{r }
made_in_Europe=length(cars[cars$Origin=="Europe"])
made_in_US=length(cars[cars$Origin=="US"])
made_in_Japan=length(cars[cars$Origin=="Japan"])
Now it's your turn! You can delete all this information and replace it by your computational document. d=data.frame(Origin=cars$Origin,Number of cars=c(made_in_Europe,made_in_US,made_in_Japan))
hist(d)
```
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment