Skip to content

Instantly share code, notes, and snippets.

@agricolamz
Created March 12, 2024 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agricolamz/91d6d04a0f328ea231051177adf8010f to your computer and use it in GitHub Desktop.
Save agricolamz/91d6d04a0f328ea231051177adf8010f to your computer and use it in GitHub Desktop.
library(tidyverse)
df <- read_csv2("data.csv")
df$CASE_LBL
df |>
select(-CASE_LBL) |>
t() |>
as_tibble() ->
transposed
colnames(transposed) <- df$CASE_LBL
transposed |>
mutate(across(everything(), function(i){ifelse(is.na(i), 0, i)})) |>
prcomp() |>
broom::augment(transposed) |>
mutate(person = colnames(df)[-1],
school = factor(school)) |>
ggplot(aes(.fittedPC1, .fittedPC2, color = school))+
geom_point()
transposed |>
mutate(across(everything(), function(i){ifelse(is.na(i), 0, i)})) |>
prcomp() |>
summary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment