How to handle multi entries?

Hello guys,

situation is eg:

example dataset
name school marks
robby highschool;secondary 10;20
Vera highschool;secondary 30;40

wanted result

name school marks
robby highschool 10
robby secondary 20
Vera highschool 30
Vera secondary 40

how can i become the result with r code, my initial dataset to work on is very big (5000 lines and 84 columns), so multiple columns have multie entries with separator ; and entries are not always of same length, so tidyr::separate_rows() got stuck on it. can some one help me with this problem?

thank you very much and kind regards,

Nobel

You say entries are not always the same length. Within a given record (row), can we assume that all multi-entry columns contain the same number of entries?

I think this will work. I am using {data.table} to do this so you will likely have to install {data.table}

```

install.packages("data.table")

```

Then

```

Load packages -----------------------------------------------------------

library(data.table)

Load data ---------------------------------------------------------------

DT<- data.table (name = c("robby", "Vera"),
school = c("highschool;secondary", "highschool;secondary"),
marks = c("10;20", "30;40"))

#Reshape data ------------------------------------------------------------

DT[, c("high", "sec") := tstrsplit(school, ";")][ , c("hmrk", "secmark") := tstrsplit(marks, ";")]
DT1 <- DT[, !c("school", "marks")] # drop unneeded variables

DT2 <- melt(DT1,
id.vars = c("name", "high", "sec"),
measure.vars = c("hmrk", "secmark"),
variable.name = "School",
value.name = "Mark")

DT2
```

prubin: what i mean is i get following error with tidyr::separate_rows(): r Error in separate_rows(): ! In row 89, can't recycle input of size 3 to size 2.