【问题标题】:R is not reading my csv file properly?R 没有正确读取我的 csv 文件?
【发布时间】:2015-06-19 12:13:28
【问题描述】:

我是 R 编程语言的新手。我可以将此 csv 文件加载到 R 中。它是分号分隔的 csv 文件。共有33个属性。但 R 将其读取为 1 列,数据集的链接是

https://archive.ics.uci.edu/ml/datasets/Student+Performance#

我在 R 中读取 csv 文件时尝试使用 sep(";")。我还尝试将各种格式从 csv 转换为文本、dif,但没有任何效果。

感谢您的帮助。

【问题讨论】:

  • 你试过 read.csv() 或 read.csv2() 吗?
  • archive.ics.uci.edu/ml/machine-learning-databases/00320 。这是下载的直接链接。这个问题可能很愚蠢。但请帮助我
  • 朋友。我都试过了。没有任何作用
  • student <- read.table("student-por.csv", header=TRUE, sep=";", quote="\"", stringsAsFactors=FALSE)
  • 如果这不起作用,您应该检查您是否在正确的目录中

标签: r csv


【解决方案1】:
df1 <- read.csv('student-mat.csv', sep=";")
df2 <- read.csv('student-por.csv', sep=";")

工作没有任何问题。也许您刚刚忘记在sep";" 之间加上等号。

> str(df1)
'data.frame':   395 obs. of  33 variables:
$ school    : Factor w/ 2 levels "GP","MS": 1 1 1 1 1 1 1 1 1 1 ...
$ sex       : Factor w/ 2 levels "F","M": 1 1 1 1 1 2 2 1 2 2 ...
$ age       : int  18 17 15 15 16 16 16 17 15 15 ...
$ address   : Factor w/ 2 levels "R","U": 2 2 2 2 2 2 2 2 2 2 ...
$ famsize   : Factor w/ 2 levels "GT3","LE3": 1 1 2 1 1 2 2 1 2 1 .
....

【讨论】:

    【解决方案2】:

    使用您的数据,对我来说效果很好:

    student_por <- read.csv2("student-por.csv")
    student_mat <- read.csv2("student-mat.csv")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-30
      • 1970-01-01
      相关资源
      最近更新 更多