如何将CSV txt文件正确加载到R中 [英] How to load a CSV txt file into R correctly

查看:431
本文介绍了如何将CSV txt文件正确加载到R中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R的新手,遇到了一些简单的麻烦。我以为我了解read.table()函数,但显然没有。我正在尝试加载 http://www.stat.berkeley .edu / users / nolan / data / bikeshare.txt 导入RStudio,无论出于何种原因,它只会再次显示文本文件。我的命令是:

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.

谢谢。

推荐答案

以下是示例:

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



推荐阅读



如果您想了解有关R的更多信息,建议您使用以下免费资源。

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

这篇关于如何将CSV txt文件正确加载到R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆