Is it possible to use read.table to read a data set in which variables and numbers appear in the same column? Here is an example that does not work, followed by matrix which does work:
aa <- 10
bb <- 20
my.data1 <- read.table(text = '
aa 0
0 bb
', header = FALSE, stringsAsFactors = FALSE)
my.data1
# matrix returns desired output
my.data2 <- matrix(c( aa, 0,
0, bb ), nrow = 2, ncol = 2, byrow = TRUE)
my.data2
# [,1] [,2]
# [1,] 10 0
# [2,] 0 20
My guess is that text converts aa and bb to text, but can this be avoided while still using read.table?
str(my.data1)
'data.frame': 2 obs. of 2 variables:
$ V1: chr "aa" "0"
$ V2: chr "0" "bb"
matrix? - Mark Miller