There is a tricky behaviour of making a matrix as one column of a data.frame or a S4Vector DataFrame, details is in the following, who knows the underlying reason for this? And is this consider acceptable use of the S4Vector DataFrame, or is this too much hack and shall be discouraged.
S4Vector DataFrame behaviour:
>library(S4Vectors)
>m <- matrix(c(1, 2, 3, 4), nrow = 2, ncol = 2)
>df <- DataFrame(col_1 = "abc", col_2 = rep(0, nrow(m)))
>df$ <- m
>df
DataFrame with 2 rows and 2 columns
col_1 col_2
character matrix
1 abc 1 3
2 abc 2 4
Traditional data.frame behaviour:
>m <- matrix(c(1, 2, 3, 4), nrow = 2, ncol = 2)
>df <- data.frame(col_1 = "abc", col_2 = rep(0, nrow(m)))
>df
col_1 col_2
1 abc 0
2 abc 0
>df$col_2 <- m
>df
col_1 col_2.1 col_2.2
1 abc 1 3
2 abc 2 4
Of course, here you can also choose to use the I() function to change the behaviour, which was discussed in another post as in the comments below.