miandai 有些数据的分隔符是3个字符,但是read.csv函数中sep只能是1个字符,怎么读取呢?难道非得先用readLines读取,然后再用strsplit处理吗? 例如下面的数据,分隔符为“[=]” T<=>3939[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>tieba.baidu.com/f[=]A<=>3033e[=]B<=>560486[=]V<=>5.3.0.806 T<=>3942[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>tieba.baidu.com/f[=]A<=>3033e[=]B<=>e046e[=]V<=>5.3.0.806 T<=>3944[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>about:blank[=]A<=>3033e[=]B<=>604a8[=]V<=>5.3.0.806 T<=>3946[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>tieba.baidu.com/p/1638664170[=]A<=>3033e[=]B<=>604a8[=]V<=>5.3.0.806 T<=>4195[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>tieba.baidu.com/f[=]A<=>3033e[=]B<=>e046e[=]V<=>5.3.0.806 T<=>4198[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>tieba.baidu.com/f[=]A<=>3033e[=]B<=>580486[=]V<=>5.3.0.806 T<=>4202[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>tieba.baidu.com/p/1638440985[=]A<=>3033e[=]B<=>130488[=]V<=>5.3.0.806 T<=>4217[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>image.baidu.com/i[=]A<=>3033e[=]B<=>17047c[=]V<=>5.3.0.806 T<=>4219[=]P<=>360chrome.exe[=]I<=>4376[=]U<=>image.baidu.com/i[=]A<=>3033e[=]B<=>17047c[=]V<=>5.3.0.806 </p>
miandai 在帖子http://cos.name/cn/topic/106840 中找到一个解决方法: 1、用readLines读取数据:rl<-readLines("filename"); 2、再用gsub把分隔符替换成逗号:gb<-gsub("\\[=\\]",",",rl); 3、最后用谢益辉的方法:read.table(textConnection(gb), sep = ',') 大功告成! 不知道有没有更好的方法,像read.csv一样一步到位,只是允许分隔符为多个。