Zack Vlliet
Zack Vlliet

Reputation: 63

How to load a CSV txt file into R correctly

I'm very new to R, and having some simple trouble. I thought I understood the read.table() function, but apparently not. I'm trying to load "http://www.stat.berkeley.edu/users/nolan/data/bikeshare.txt" into RStudio, and for whatever reason, it only displays the text file again. My command was:

read.table("http://www.stat.berkeley.edu/users/nolan/data/bikeshare.txt",
           sep=",", 
           header=True)

Any help is much appreciated.

Thanks.

Upvotes: 1

Views: 1750

Answers (1)

Technophobe01
Technophobe01

Reputation: 8666

Here is an example:

Code Example:

URL <- "http://www.stat.berkeley.edu/users/nolan/data/bikeshare.txt"
bikeshare <- read.table(URL, sep=",", header=TRUE)
head(bikeshare)

Example Output:

> URL <- "http://www.stat.berkeley.edu/users/nolan/data/bikeshare.txt"
> bikeshare <- read.table(URL, sep=",", header=TRUE)
> head(bikeshare)
  instant     dteday season yr mnth hr holiday weekday workingday weathersit temp  atemp  hum windspeed casual registered cnt
1       1 2011-01-01      1  0    1  0       0       6          0          1 0.24 0.2879 0.81    0.0000      3         13  16
2       2 2011-01-01      1  0    1  1       0       6          0          1 0.22 0.2727 0.80    0.0000      8         32  40
3       3 2011-01-01      1  0    1  2       0       6          0          1 0.22 0.2727 0.80    0.0000      5         27  32
4       4 2011-01-01      1  0    1  3       0       6          0          1 0.24 0.2879 0.75    0.0000      3         10  13
5       5 2011-01-01      1  0    1  4       0       6          0          1 0.24 0.2879 0.75    0.0000      0          1   1
6       6 2011-01-01      1  0    1  5       0       6          0          2 0.24 0.2576 0.75    0.0896      0          1   1

Recommended Reading

If you want to learn more about R, I'd recommend the following free resources.

Upvotes: 1

Related Questions