Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Stat10010: Help importing data with R

  • 01-11-2010 2:57pm
    #1
    Registered Users, Registered Users 2 Posts: 71 ✭✭


    Ok, im having some trouble importing data with R (Lab 2). I have a txt file called pulse.txt which i have saved to my C drive in a folder called statistics and so the path name for the pulse.txt file should be "C:\Statistics\Pulse.txt".

    Sooooo, i type in: pulse<-read.table(“C:\statistics\pulse.txt”,header=TRUE)
    but i repeatedly get this error message:
    Error: unexpected input in "pulse <-read.table(“"

    If anyone can please give me some advice I'd be so greatfull because i really am on the brink of losing my mind after trying to get that one line right for the last 2 hours.... Thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 3,803 ✭✭✭El Siglo


    jripper wrote: »
    Ok, im having some trouble importing data with R (Lab 2). I have a txt file called pulse.txt which i have saved to my C drive in a folder called statistics and so the path name for the pulse.txt file should be "C:\Statistics\Pulse.txt".

    Sooooo, i type in: pulse<-read.table(“C:\statistics\pulse.txt”,header=TRUE)
    but i repeatedly get this error message:
    Error: unexpected input in "pulse <-read.table(“"

    If anyone can please give me some advice I'd be so greatfull because i really am on the brink of losing my mind after trying to get that one line right for the last 2 hours.... Thanks.

    Have you changed the directory of your files in R? Such that you set the directory to your "C:\Statistics" file? If you do it like that, you can import your file like:
    pulse<-read.table("pulse.txt", header=T)

    Also, have you checked your file for any spaces between characters? R tends to read these as separate columns. Make sure that you have no spaces between any characters in your excel sheet and then if you have to, save it as a tab delimited file and see if it works again.


  • Registered Users, Registered Users 2 Posts: 71 ✭✭jripper


    Just got it, went to file and changed the working directory then typed in the command you suggested. Worked perfectly, now i can do my asgnmnt. Thanks for taking the time to reply, you're a hero. ;-)


  • Registered Users, Registered Users 2 Posts: 13,074 ✭✭✭✭bnt


    Since R is orignally UNIX software, I expect it has problems handling backslashes in file paths. You could try replacing them with forward slashes ("C:/Statistics/Pulse.txt") or double backslashes ("C:\\Statistics\\Pulse.txt"), to see if that helps.

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Moderators, Education Moderators, Motoring & Transport Moderators Posts: 7,396 Mod ✭✭✭✭**Timbuk2**


    Make sure you have the location exactly right (including capital letters), and also I would use double backslashes as such (this is also the directory I use).

    data<-read.table("H:\\FILES\\Statistics\\file.txt", header=TRUE)

    edit: bnt got there before me :o


  • Registered Users, Registered Users 2 Posts: 3,803 ✭✭✭El Siglo


    No, it was a working directory problem (happens a lot when you start using the programme, takes time to get into the habit of setting the directory). When you don't set this to where you want to save etc... R automatically seeks out the "Documents Library" or "My Documents" as a default and that's no use to anyone.

    Op, you might want to invest in a copy of "Statistics: An Introduction Using R" by Michael Crawley. He's a website of tasks, commands etc... to work with while reading the book. It only costs about €25 but is a really handy book to have.


  • Advertisement
  • Closed Accounts Posts: 6,151 ✭✭✭Thomas_S_Hunterson


    try something like this:
    data<-read.table(file.choose(), header=TRUE)
    

    Avoids the hassle of escaping characters.


Advertisement