I have the following table:
column1 column2
1 aaa^bbb
2 aaa^bbb|ccc^ffffd
I would like to have a output file as follows:
The easiest way to do what you are after, is just use strsplit. For example,
> x = c("aaa^bbb", "aaa^bbb|ccc^ffffd")
> ## Split the vector on ^ OR |.
> ## Since ^ and | are special characters
> ## we need to escape them: \\^ and \\|
> ## Split by column.
> new_x = unlist(strsplit(x, "\\|"))
> ## Split by row
> new_x = unlist(strsplit(new_x, "\\^"))
> new_x
[1] "aaa" "bbb" "aaa" "bbb" "ccc" "ffffd"
> ## Change the vector back into a matrix
> dim(new_x) = c(2,3)
> ## Transpose to get correct shape
> t(new_x)
[,1] [,2]
[1,] "aaa" "bbb"
[2,] "aaa" "bbb"
[3,] "ccc" "ffffd"
You could probably combine the splitting step, but I don't have enough knowledge to your data format to be confident that it will always work.