[R] Problem importing .txt file

R. Michael Weylandt michael.weylandt at gmail.com
Wed Jan 18 23:09:32 CET 2012


Responses will be sent to the list and bounced to you if you are
subscribed: most replies also cc the thread and OP (and I think the
server notes this so you don't get two copies).

It looks like it may be an encoding problem in the .txt file. If your
data allows it, try opening it up with a text editor and saving it
again as something like Latin-1. Everything looks ok on the R end of
things.

Michael

On Wed, Jan 18, 2012 at 4:39 PM, Berneet Kaur
<berneet.kaur at ucdmc.ucdavis.edu> wrote:
>
>
>   Hello, I hope I am doing this correctly, though I am not sure if a response
>   will be posted somewhere or if I will get a direct response. I am trying to
>   import a .txt table in my class on R and for some reason, the header gets
>   altered and I can no longer read the data. No one in my class had this
>   problem and the instructors were not sure how to fix it.
>   Here is the text table:
>   Kind Fatness Wt
>   Ewe 4 10.3
>   Ewe 8 11.9
>   Ewe 11 15
>   Ewe 15 17.1
>   Ewe 15 18.7
>   Ram 5 12.4
>   Ram 4 14.3
>   Ram 10 16.6
>   Ram 8 18.8
>   Ram 14 21.9
>   Here is the code that I copied from the instructors handout (simple cut and
>   paste, no alterations):
>   Lambs = read.table("Lambs.txt", header = TRUE)
>   > Lambs
>   ï..Kind Fatness Wt
>   1 Ewe 4 10.3
>   2 Ewe 8 11.9
>   3 Ewe 11 15.0
>   4 Ewe 15 17.1
>   5 Ewe 15 18.7
>   6 Ram 5 12.4
>   7 Ram 4 14.3
>   8 Ram 10 16.6
>   9 Ram 8 18.8
>   10 Ram 14 21.9
>   > par(mfrow = c(1, 2))
>   > plot(Fatness ~ Kind, data = Lambs)
>   Error in eval(expr, envir, enclos) : object 'Kind' not found
>
>
>   I think it is because the "Kind" header got altered into " ï..Kind" and it
>   can no longer identify the object.
>   Can anyone help?
>   Thanks
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list