The The R Primer logo Primer

Read data from a text file

You want to import a dataset stored in an ASCII text file.

Solution: Use the read.table function.

> indata <- read.table("mydata.txt", header=TRUE)
> indata
  acid digest  name
1 30.3   70.6  
2 29.8   67.5  Eeny
3   NA   87.0 Meeny
4  4.1   89.9  Miny
5  4.4      .   Moe
6  2.8   93.1     .
7  3.8   96.7      

See rule 1.1 in The R Primer for more information.

Back to tips.