I have a dataframe that includes a series of information that identifies a group of people by their current board memberships. It looks like this:
company_board <- c("company1", "company2", "company3; company 1", "", "")
nonprofit_board <- c("nonprofit1", "", "nonprofit5; nonprofit2", "", "nonprofit3")
df <- data.frame(company_board, nonprofit_board, stringsAsFactors = FALSE)
I want to convert these into simple 1 if there is information in the cell or 0 if there is no data recorded. So for the example I've just given:
company_board <- c("1", "1", "1", "0", "0")
nonprofit_board <- c("1", "0", "1", "0", "1")
df <- data.frame(company_board, nonprofit_board, stringsAsFactors = FALSE)
I know how to use str_extract with [:alnum:] to get the cells that should be 1 but I can't figure out how to then replace these cells with 1 (and the remainder with 0). Any help would be greatly appreciated!