0% found this document useful (0 votes)
3 views3 pages

R Markdown Guide for Data Analysis

Uploaded by

dixitmuskan635
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

R Markdown Guide for Data Analysis

Uploaded by

dixitmuskan635
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

---

title: "Untitled"
author: "Muskan"
date: "2024-11-02"
output: word_document
---

```{r setup, include=FALSE}


knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for


authoring HTML, PDF, and MS Word documents. For more details on using R Markdown
see <[Link]

When you click the **Knit** button a document will be generated that includes both
content as well as the output of any embedded R code chunks within the document.
You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}


plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent
printing of the R code that generated the plot.
[Link]("tidyverse")
library(tidyverse)

#1
scores <-
tibble(
name = c("mike", "carol", "greg", "marcia", "peter", "jan", "bobby", "cindy",
"alice"),
school = c("south", "south", "south", "south", "north", "north", "north",
"south", "south"),
teacher = c("johnson", "johnson", "johnson", "johnson", "smith", "smith",
"smith", "perry", "perry"),
sex = c("male", "female", "male", "female", "male", "female", "male", "female",
"female"),
math_score = c(4, 3, 2, 4, 3, 4, 5, 4, 5),
reading_score = c(1, 5, 2, 4, 5, 4, 1, 5, 4)
)

scores%>%
slice(1:3)

scores%>%
arrange(name)
scores%>%
arrange(sex)
female<-scores%>% filter(sex=="female")%>% summarise(mean(reading_score))
male<-scores%>% filter(sex=="male")%>% summarise(mean(reading_score))

scores%>% arrange(school,teacher,sex,math_score,reading_score)

#2
scores%>% select(-sex)

scores%>% select(-math_score,-reading_score)

scores%>% select(sex,everything())

#3
scores%>% filter(math_score>=70)

scores%>% filter(math_score>=4 & reading_score>=3)

scores%>% filter(school=="south")

scores%>% filter(math_score<3 | reading_score <3)

scores%>% filter(reading %in% c(2,3,4))

#4
scores%>% group_by(sex)%>%
filter(mean(math_score)==4)

#5
scores%>% mutate(math_reading_avg=(math_score+reading_score)/2)

scores%>% mutate(high_math_achiever=ifelse(math_score>=4,TRUE,FALSE))

mean_reading_score<-mean(scores$reading_score,[Link]=TRUE)
scores%>% mutate(reading_score_centered=reading_score-mean_reading_score)

[Link](123)
scores%>% mutate(science_score=sample(1:5,nrow(scores),replace=TRUE))

#6
scores%>%
group_by(sex) %>% mutate(math_score_centred_by_sex=math_score-
mean(math_score,[Link]=TRUE))
%>%ungroup()

scores%>% group_by(class) %>% mutate(no_of_students_in_class=n())%%>% ungroup()

#7
mean_reading_score<-mean(scores$reading_score,[Link]=TRUE)
scores%>% summarize(mean_reading_score)

median_reading_and_math_score<-
median(scores$reading_score,scores$math_score,[Link]=TRUE)
scores%>% summarize(median_reading_and_math_score)

#8
scores%>% group_by(school) %>% summarize(max_math_score=max(math_score))
#9
scores%>% select(-teacher) %>%mutate(mean_score=(math_score+reading_score)/2) %>%
arrange(mean_score)

Common questions

Powered by AI

Filtering students with a math score of 4 or higher and a reading score of 3 or higher identifies a subset of students who perform relatively well in both subjects. This approach allows teachers or analysts to focus on students who may require different teaching strategies or recognition, to further understand their learning capabilities and possibly improve their performance in other areas .

The average reading scores based on gender are calculated using the 'filter()' and 'summarise()' functions from 'dplyr'. The dataset is filtered by gender, and then the 'summarise(mean(reading_score))' function computes the mean reading score for each gender group. Specifically, females and males have their reading scores averaged separately, allowing for a direct comparison between the two groups .

The addition of a 'science_score' variable through random number generation augments the dataset with a simulated measure of performance in science. This provides a ground to explore correlations between disciplines and potentially infer outcomes in comprehensive performance analysis. The use of random sampling allows for a diverse set of data points mimicking a real-world scenario where science performance might vary independently from other scores .

The dataset is organized into a tibble with columns for 'name', 'school', 'teacher', 'sex', 'math_score', and 'reading_score'. These variables are central to the analyses because they capture key demographic and academic performance information. Analyses in the document, such as sorting, filtering, and summarizing, focus on these variables to explore relationships between gender, academic scores, and educational settings .

The 'echo = FALSE' parameter in an R Markdown code chunk is used to prevent the printing of the R code that generated the output. This is useful for decluttering the document by only displaying the results of the code, such as plots or tables, while hiding the actual code from view .

The 'dplyr' package in R enhances data manipulation by providing a set of intuitive functions that perform data cleaning and transformation tasks. In the document, functions like 'filter()', 'arrange()', 'summarise()', and 'mutate()' are used to organize, filter, and manipulate the dataset efficiently. For instance, 'filter()' is used to select rows based on conditions, 'arrange()' sorts the data, 'summarise()' computes summary statistics, and 'mutate()' adds new variables .

The 'tidyverse' package is a collection of R packages designed for data science, providing an easy-to-learn environment for data manipulation and visualization. In the document, 'tidyverse' is used to perform various data wrangling tasks like filtering, arranging, and summarizing. It benefits users by standardizing syntax across different data manipulation tasks, enhancing readability, and reducing coding errors through consistent naming conventions and functions .

Filtering for students with extreme scores can lead to a small, potentially non-representative sample size, which might skew analyses and interpretations. Additionally, such students may have unique circumstances impacting their scores. To address these challenges, one should ensure robust statistical methods that control for sample size effects, possibly supplementing with qualitative insights or additional data points. Analysts may also consider sensitivity analyses to confirm the robustness of conclusions drawn from these extreme cases .

Grouping data by 'sex' and calculating centered math scores by gender allows for an analysis of gender-specific performance relative to the average math score within each group. This approach helps identify deviations or patterns unique to each gender, providing insights into potential disparities or biases in educational outcomes based on gender .

Creating the 'math_reading_avg' variable allows for a combined assessment of a student's performance in mathematics and reading. By averaging the two scores, this new metric provides a more holistic view of a student's overall academic performance, simplifying the comparison and potential identification of students who excel or need improvement across both subjects .

You might also like