rowwise %>% mean

Series: IDHTG

When you have data from a survey, the responses for each item are most often listed in different variables. Generally you have to average across the items to get a mean value for that scale for each participant. But dealing with calculations across rows is sometimes difficult in R. load packages + make some data library(tidyverse) pID <- c("p1", "p2", "p3", "p4", "p5", "p6") item1 = sample(1:7, 6, replace=T) item2 = sample(1:7, 6, replace=T) item3 = sample(1:7, 6, replace=T) item4 = sample(1:7, 6, replace=T) item5 = sample(1:7, 6, replace=T) survey <- data.

By Package Build

May 24, 2023

how to do t-tests

Series: IDHTG

I was trying to work out how to do t-tests using my own data and the lsr package but ended up working with Dani’s AFL data from her book while trying to work out why R insisted that my outcome variable wasn’t numeric (it definitely was). Turns out that the lsr package doesn’t deal well with tibbles (which are created by default when you use read_csv to get your data) but if you use read.

By Jen Richmond

April 25, 2023

error bars on plots

Series: IDHTG

Repurposing this APA figures post as a IDHTG post. As I write my first paper reporting data analysis coming out of R (woot!!!), here are some notes summarising all the googling I have done this morning about how to produce APA style figures in ggplot. Load libraries Start by loading tidyverse to get ggplot, here to make finding the data easy, and papaja to get the theme_apa() function.

By Jen Richmond

April 25, 2023

colours that R knows

Series: IDHTG

I have been working through the ggplot R Advent calendar by Kiirsti Owen with some lovely RLadies friends and we got up to Day 15 where we started controlling colours in ggplot with scale_fill_manual(). Our immediate question was “how to you know what the names of the colours that R knows are?” This is a “I don’t have to google” post about finding the colours that R knows about. trees %>% ggplot(aes(x=type, y=height))+ geom_boxplot(aes(fill=type), colour="black")+ theme_classic()+ scale_fill_manual(values=c("darkgreen", "firebrick2", "mediumseagreen")) You can have R list the names of all the colours it knows (there are 657 of them) using the colours() function, but that is not so useful if you want to see the difference between hotpink1 and hotpink2.

By Jen Richmond

December 14, 2022

how to subset strings

Series: IDHTG

Sometimes you have a column in your data frame that is text, but there is some of it that you don’t need. Lets say your data looks like this… df <- data.frame(animals = c("this is a bear", "this is a lion", "this is a tiger")) df ## animals ## 1 this is a bear ## 2 this is a lion ## 3 this is a tiger And perhaps only want the animal names… you can use sub_str() from the stringr package to strip out the extra characters.

By Jen Richmond

September 29, 2022