How do I import a survey into R Studio from an internet address?

  • Thread starter Thread starter BubblesAreUs
  • Start date Start date
  • Tags Tags
    Survey
AI Thread Summary
The discussion revolves around loading a survey dataset into R Studio for analysis. The user is attempting to use the provided code to read a CSV file from a URL, but encounters errors indicating that the objects 'survey' and 'pulse' are not found. The main issue highlighted is that the user needs to ensure the CSV file is downloaded and saved locally on their computer, as R cannot read directly from the internet in this context. To resolve the errors, it is recommended to check the current working directory using the getwd() function and place the CSV file in that directory. The user can also change the working directory with the setwd() function to point to the correct folder where the file is stored.
BubblesAreUs
Messages
43
Reaction score
1
I am using R studio for a practical and I need to load a survey. It suggests that I place the following into the R template that I was provided:

survey=read.csv("http://www.maths.usyd.edu.au/u/UG/IM/STAT2012/r/survey.csv")
attach(survey)
pulse.sf=pulse[smoke==1 & sex==2]
pulse.sf

Template link http://www.maths.usyd.edu.au/u/UG/IM/STAT2012/r/p4.Rnw.

I have no clue WHERE one inserts these lines. I try the following:

urvey <- read.csv(file="http://www.maths.usyd.edu.au/u/UG/IM/STAT2012/r/survey.csv")
attach(survey)
## Error in attach(survey): object ’survey’ not found
pulse.sf=pulse[smoke==1 & sex==2]
## Error in eval(expr, envir, enclos): object ’pulse’ not found
pulse.sf
## Error in eval(expr, envir, enclos): object ’pulse.sf’ not
foun

What's going on? I can actually download the survey and view it on Excel. The problem is drawing the data into R studio.

Appreciate any help that I can get.
 
Physics news on Phys.org
It works for me. So some questions:
1) Did you actually download the survey and put it in your computer?
2) What folder did you put in the survey? Type getwd() in R to see what folder you should put in the survey. For example if getwd() yields C:\Documents, then you should put the csv file in that folder and then access it by survey <- read.csv("survey.csv")
3) You can change your folder in R by setwd https://stat.ethz.ch/R-manual/R-devel/library/base/html/getwd.html
 
  • Like
Likes FactChecker
@micromass is right. You have to have the file on your computer. You can not read it from an internet address.
 
Back
Top