Creating a yes/no table in R

Hello.
I am trying to create a yes/no table based on the following data.


I wanted the economic variables as columns- so I would have to make it a wide table first.

Any ideas of how to do this?

r4ds textbook, chapter relating to tidy-data, and pivoting wider :
12 Tidy data | R for Data Science (had.co.nz)

when I pivot wide, I don't have a third variable to fill in the columns. And my study codes get grouped into one cell. as seen in the image. rather, i need to find a way to add the yes/no to fill the columns

I don't exactly know what you mean by yes/no table. would everything be yes, as if its not in the initial table its not known about, and when rearranging the info in the initial table nothing should be lost... i.e. what would correspond to a 'no' ?

Completely guessing, but are you trying to count the combinations ?

library(tidyverse)
(some_data <- data.frame(
  Code=c(letters[1:5],letters[1:3]),
  Out.Subind = c(1:5,1:3)
))

# maybe you want to count?

some_data %>% group_by_all() %>% count() %>%
  pivot_wider(names_from=c("Code","Out.Subind"),
              values_from="n")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.