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
Click For Summary
SUMMARY

To successfully import a survey into R Studio, users must first download the CSV file to their local machine instead of attempting to read it directly from an internet address. The correct command to load the survey is survey <- read.csv("survey.csv") after placing the file in the working directory, which can be verified using getwd(). Additionally, users can change their working directory with setwd() to ensure the file is accessible. Errors such as "object not found" occur when R cannot locate the specified data.

PREREQUISITES
  • Basic understanding of R programming
  • Familiarity with R Studio interface
  • Knowledge of CSV file format
  • Experience using R functions like read.csv() and attach()
NEXT STEPS
  • Learn how to use getwd() and setwd() for managing working directories in R
  • Explore data manipulation techniques in R using the dplyr package
  • Investigate error handling in R to troubleshoot common issues
  • Study how to visualize data in R using the ggplot2 package
USEFUL FOR

Data analysts, statisticians, and students using R for data analysis who need guidance on importing and managing datasets in R Studio.

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   Reactions: FactChecker
@micromass is right. You have to have the file on your computer. You can not read it from an internet address.
 

Similar threads

Replies
3
Views
8K