How to load a CSV txt file into R correctly

时光怂恿深爱的人放手 提交于 2019-12-11 14:12:45

问题


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.


回答1:


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.

  • Quick R Web Site
  • R for Data Science - Hadley Wickham
  • Advanced R - Hadley Wickham


来源:https://stackoverflow.com/questions/48433228/how-to-load-a-csv-txt-file-into-r-correctly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!