开发者

read.table as it is

开发者 https://www.devze.com 2022-12-20 14:31 出处:网络
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:

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

精彩评论

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