0

我的数据存储在一个文本文件中,如下所示:

1, { {0, 1}, {1, 0}, {2, 6} }

2, { {0, 3}, {2, 2}, {0, 1} }
...

第一个元素是整数,第二个元素是二维数组。是否有将其读入 R 的函数?

4

1 回答 1

4
 data.frame( lapply( read.csv(text=
"1, { {0, 1}, {1, 0}, {2, 6} } # will read the line as mostly character columns 
 2, { {0, 3}, {2, 2}, {0, 1} } # with '{' and '}' just as non-syntactic characters
", header=FALSE              ), 
     function(x) as.numeric( gsub("[^[:digit:]]", "", x) ) 
           )        )
#----------------------
  V1 V2 V3 V4 V5 V6 V7
1  1  0  1  1  0  2  6
2  2  0  3  2  2  0  1
于 2012-06-04T23:26:24.890 回答