Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I have an ascii dataset which consists of three columns, but only the last two are actual data. Now I want to create a dotchart of the data by using read.csv(file = "result1", sep= " "). R reads all three columns. How do I avoid this?

share|improve this question
3  
I'll leave it here, but please ask future basic R questions on StackOverflow. – mbq Oct 10 '11 at 15:59

2 Answers

up vote 7 down vote accepted

You can use the colClasses argument to read.csv to select the columns you want. In this case, you can set colClasses to c("NULL", NA, NA)

read.csv(file="result1", sep=" ", colClasses=c("NULL", NA, NA))

More generally, you can use colClasses to specify the particular types of columns; NA means to use the default approach which is to try and figure out what the column is automatically. See the help page for read.csv for more details.

share|improve this answer

Another option is to read in the whole file, but keep only two of the columns, e.g.:

read.csv(file = "result1", sep = " ")[ ,1:2]

or, using column names, eg. if columns are named 'col1, col2, col3'

read.csv(file = "result1", sep = " ")[ ,c('col1', 'col2')]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.