Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

r - read.table reads "T" as TRUE and "F" as FALSE, how to avoid?

I have a file with the data c("A","T","B","F").

When I use:

read.csv(myfile,header=F,stringsAsFactors=F)

R interprets character T as TRUE and F as FALSE

Am I doing anything wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If all your columns are characters then try this:

# replace text = . with your filename
read.csv(text="A,B,T,T", header=FALSE, stringsAsFactors=FALSE, 
            colClasses = c("character"))

Else, you'll have to pass the type of each column in colClasses as: colClasses = c("numeric", "numeric", "character", ...)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...