I have this data frame in R.
df <- read.table(text="
nr first second
n1 a;a;b 1;1;7
n2 c;c 3;3
n3 d;e 4;4", header=T, stringsAsFactors=FALSE)
And, I want to convert this to a data frame like this.
nr first second
n1 a 1
n1 b 7
n2 c 3
n3 d 4
n3 e 4
For each row, I only want to keep the unique elements in 'first'; and for each unique element I want a separate row.
Further, the columns 'first' and 'second' are linked. For example, 'b' in 'a;a;b' corresponds to 7 in '1;1;7'. I only want to keep the element in 'second' that corresponds to the element in 'first'.