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 seta开发者_如何学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=","))
精彩评论