Imagine I have the following stacked data matrix:
mY <- data.frame(matrix(c(c(1:10),c("A 1","A 1","A 1","A 1","A 1","B 1","B 1","B 1","B 1","B 1")),10))
Resulting in:
X1 X2
1 1 A 1
2 2 A 1
3 3 A 1
4 4 A 1
5 5 A 1
6 6 B 1
7 7 B 1
8 8 B 1
9 9 B 1
10 10 B 1
This is just an example of a data frame which I want to unstack, where entries in X2 contain a space character. It could also have been 'hot dog', or 'boiled egg'.
When I use
mB <- unstack(mY, X1~X2)
I get
A.1 B.1
1 1 6
2 2 7
3 3 8
4 4 9
5 5 10
Notice that the name of the columns have changed to A.1 and B.1, which were previously defined as 'A 1' and 'B 1'. When I use mB["A 1"] it returns null, whereas mB["A.1"] returns column A.1. How can I overcome this?
Thanks in advance.