Ivri
Ivri

Reputation: 2219

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 as.is=!stringsAsFactors, but got the following error message:

 error: object stringsAsFactors not found.  

Anybody can help?

Upvotes: 4

Views: 6861

Answers (1)

Ivri
Ivri

Reputation: 2219

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=","))

Upvotes: 3

Related Questions