From 020c82b5cd0c7c41f22f73700c782095e812f533 Mon Sep 17 00:00:00 2001 From: NourElh <734092651fcdd5add927271f472626a6@app-learninglab.inria.fr> Date: Tue, 1 Nov 2022 13:30:18 +0000 Subject: [PATCH] Update exercice_en.Rmd --- module2/exo4/exercice_en.Rmd | 47 +++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/module2/exo4/exercice_en.Rmd b/module2/exo4/exercice_en.Rmd index 13b258d..26578b7 100644 --- a/module2/exo4/exercice_en.Rmd +++ b/module2/exo4/exercice_en.Rmd @@ -9,25 +9,48 @@ output: html_document ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` +```{r} +cars=read.csv("./cars.csv",header = T, sep=";") +head(cars) +``` -## Some explanations - -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 . +# Data Analysis +## Get the cars having 8 cylinders +```{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} -summary(cars) +## Get the names of the cars having biggest horsepower +```{r } +d=cars[cars$Horsepower==max(cars$Horsepower)] +names=d['Car'] ``` -It is also straightforward to include figures. For example: -```{r pressure, echo=FALSE} -plot(pressure) +## Get all the cars made in Europe +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 -- 2.18.1