Re: [R] Decompose df1 into another df2 based on values in df1

2021-05-27 Thread Eik Vettorazzi
A tidyverse-ish solution would be library(dplyr) library(tidyr) library(tibble) # max cols to split values into seps<-max(stringr::str_count(unlist(d1),"[/|]"))+1 d1 %>% pivot_longer(S1:S5, names_to="S") %>% mutate(value=na_if(value,"w")) %>% separate(value,"[/|]", into=LETTERS[1:seps], fill=

Re: [R] Decompose df1 into another df2 based on values in df1

2021-05-26 Thread Bert Gunter
Thank you for the reprex. However your specification was too vague for me to know exactly what your data are like, so I tried to assume the most general possibility, with the consequence that I may be giving you an answer to the wrong question. Hopefully, you can adjust as needed to get what you wa

[R] Decompose df1 into another df2 based on values in df1

2021-05-26 Thread Adrian Johnson
Hello, I am trying to convert a df (given below as d1) into df2 (given below as res). I tried using loops for each row. I cannot get it right. Moreover the df is 25 x 500 in dimension and I cannot get it to work. Could anyone help me here please. Thanks. Adrian. d1 <- structure(list(S1 =