Read.table since it is

I am trying to read data from a csv file, but instead, for example, 001000 I get 1000 in my data.
I tried to install as.is=!stringsAsFactorsbut received the following error message:

 error: object stringsAsFactors not found.  

Can anybody help?

+3
source share
1 answer

I found a workaround: add a colClassesdescription

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

How to convert a character to a vector:

It’s easier to use delimiters in the data, because finally you get the character and convert it, for example. vector, you should do something 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=","))
+2
source

Source: https://habr.com/ru/post/1733631/


All Articles