开发者

read.table as it is

I'm trying to read data from csv file, but instead of e.g. 001000 I get 1000 in my data.

I've tried to set a开发者_如何学Cs.is=!stringsAsFactors, but got the following error message:

 error: object stringsAsFactors not found.  

Anybody can help?


I've found workaround: add colClasses description

data_raw <- read.table("data",
                     colClasses=c("character","character","character"),
                     sep="\t",
                     quote="\"")  

How to convert character to vector:

It's easier to use separators in data, because finally you'll get character and to convert it to e.g. vector you should do smth like:

m <- as.integer(unlist(strsplit("0,1,1,1,0",split=",")))
m
[1] 0 1 1 1 0

or

m<-as.integer(scan(textConnection("0,1,1,1,0"),sep=","))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜