[R] Problem importing .txt file

Berneet Kaur berneet.kaur at ucdmc.ucdavis.edu
Wed Jan 18 22:39:59 CET 2012



   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


More information about the R-help mailing list