r - R用read.csv读取csv文件
问题描述
使用此脚本:
# I) Go to the working directory
setwd("/home/***/Desktop/***")
# II) Verify the current working directory
print(getwd())
# III) Load te nedded package
require("csv")
# IV) Read the desired file
read.csv(file="serious-injury-outcome-indicators-2000-18-csv.csv", header=TRUE, sep=",")
我试图阅读此文件: 严重伤害结果指标:2000–18 – CSV
但是控制台中的输出并不好,有人可以尝试一下并告诉我他是否遇到了同样的问题。谢谢
解决方案
您可以直接从网站读取文件:
dta <- url("https://www.stats.govt.nz/assets/Uploads/Serious-injury-outcome-indicators/Serious-injury-outcome-indicators-200018/Download-data/serious-injury-outcome-indicators-2000-18-csv.csv")
injury <- read.csv(dta, header=TRUE)
str(injury)
# 'data.frame': 2460 obs. of 13 variables:
# $ Series_reference: chr "W_A11" "W_A11" "W_A11" "W_A11" ...
# $ Period : chr "2000-02" "2001-03" "2002-04" "2003-05" ...
# $ Type : chr "Moving average" "Moving average" "Moving average" "Moving average" ...
# $ Data_value : num 59.7 60 59 59 61.3 ...
# $ Lower_CI : num 50.9 51.2 50.3 50.3 52.5 ...
# $ Upper_CI : num 68.4 68.8 67.7 67.7 70.2 ...
# $ Units : chr "Injuries" "Injuries" "Injuries" "Injuries" ...
# $ Indicator : chr "Number" "Number" "Number" "Number" ...
# $ Cause : chr "Assault" "Assault" "Assault" "Assault" ...
# $ Validation : chr "Validated" "Validated" "Validated" "Validated" ...
# $ Population : chr "Whole pop" "Whole pop" "Whole pop" "Whole pop" ...
# $ Age : chr "All ages" "All ages" "All ages" "All ages" ...
# $ Severity : chr "Fatal" "Fatal" "Fatal" "Fatal" ...
推荐阅读
- javascript - Google Apps 脚本 - 使用文本按钮和 URL 时出错
- javascript - 这个 Export 和 Import 语法在 JavaScript 中是什么意思?
- javascript - 如何使用 Firefox 从 Javascript 网页脚本中的剪贴板读取文本?
- excel - 在 Excel VBA 中获取无效的量词
- flutter - Flutter原生android传递依赖冲突(重复类)
- node.js - Mongo 远程身份验证从一台服务器工作,但不在另一台服务器上工作
- vb.net - 在 VB.NET 中创建数据表的实例
- android - 如何接收来自 Dellking H4 蓝牙耳机的 PTT 按钮按下事件?
- python - 为什么我的代码在传递给 .exe 时不起作用?
- loops - 如何使用本地宏对数据进行子集化