This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

# Install the necessary packages if you don't have them
#install.packages("readxl")  # For reading Excel files
#install.packages("dplyr")   # For data manipulation

# Load the libraries
library(readxl)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#Assignment 1: Load dataset
data <- read_excel("C:/my_folder/old_dummy_data_for_prospective_RAs.xlsx")

#Assignment 2: Remove first 2 rows from data
data <- data[-c(1, 2), ]

#Assignment 3:Remove all participants who took less than one minute on the survey
filtered_data <- data %>%
  filter(Duration_in_seconds > 60)

# View the filtered data
print(filtered_data)
## # A tibble: 178 × 16
##    ParticipantID Duration_in_seconds sex    CDS_1 CDS_2 SBQ_1 SBQ_2 SBQ_3 SBQ_4
##    <chr>                       <dbl> <chr>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1 fakedata_003                   73 male       3     3     1     3     1     4
##  2 fakedata_010                  179 male       0     2     1     3     2     2
##  3 fakedata_011                  277 male       2     2     2     2     2     1
##  4 fakedata_012                  255 male       2     2     1     4     1     4
##  5 fakedata_013                  358 male       2     0     1     3     2     3
##  6 fakedata_014                  469 female     0     1     3     2     1     0
##  7 fakedata_015                  253 male       2     2     2     3     2     5
##  8 fakedata_016                  491 female     2     3     3     2     1     2
##  9 fakedata_017                  399 male       1     0     1     4     2     2
## 10 fakedata_018                  563 female     0     0     3     3     1     5
## # ℹ 168 more rows
## # ℹ 7 more variables: GAD_1 <dbl>, GAD_2 <dbl>, GAD_3 <dbl>, GAD_4 <dbl>,
## #   GAD_5 <dbl>, GAD_6 <dbl>, GAD_7 <dbl>
# Assignment 4: Create a total score for the Cambridge Dissociation Scale (CDS) and the Suicide Behavior Questionnaire (SBQ). 
data <- data %>% mutate(CDS_TOTAL = CDS_1 + CDS_2)
data <- data %>% mutate(SBQ_TOTAL = SBQ_1 + SBQ_2 + SBQ_3 + SBQ_4)

data %>% select(ParticipantID, CDS_TOTAL, SBQ_TOTAL) 
# Assignment 5: Create a table that shows the average suicide risk total score by sex assigned at birth (i.e., each sex variable should have its own average total score)
data %>%
  group_by(sex) %>%
    summarise(average_value = mean(SBQ_TOTAL, na.rm = TRUE))
#data %>% select(ParticipantID, CDS_TOTAL,  SUICIDE_RISK_MALE) 

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.