0

With this script:

# 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=",")

I tried to read this file: Serious injury outcome indicators: 2000–18 – CSV

But the output in the consol is not well, Can someone try it and tell me if he encoutred the same problem. Thanks

6
  • Another option is to load library(readr) and use read_csv. This loads data as a data.frame and a tibble. Commented Oct 15, 2020 at 14:49
  • I've never seen the csv package used - there's a read.csv built in to R. Have you tried the default version? Commented Oct 15, 2020 at 15:07
  • But more importantly, can you be more specific than "the output in the consol is not well"? Is there an error message? Any warnings? What do you see? Why do you think it is wrong? Perhaps try assigning the result d <- read.csv(...) and have a look at d? Commented Oct 15, 2020 at 15:08
  • i think you would profit from adding dec="." like so: df<-read.table("C:/Users/***/serious-injury-outcome-indicators-2000-18-csv.csv", header=T, sep=",", dec=".") but other than that it looks fine Commented Oct 15, 2020 at 15:11
  • @D.J Why? dec = "." is the default. And why switch to read.table? Commented Oct 15, 2020 at 15:49

1 Answer 1

2

You can read the file directly from the website:

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" ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.