PDA

View Full Version : Loading data into R



gambs
02-25-2009, 07:25 AM
I am very new to R and computing in general.I am trying to load the following data into R but am having trouble. I saved this data in Notepad then to a file c:\temp\hotdogs.txt but then can't seem to get R to read it.

I am using
hotdogs<-read.table("data/hotdogs/data", header = T)

Any suggestions???? Please help.



Type Calories Sodium
Beef 186 495
Beef 181 477
Beef 176 425
Beef 149 322
Beef 184 482
Beef 190 587
Beef 158 370
Beef 139 322
Beef 175 479
Beef 148 375
Beef 152 330
Beef 111 300
Beef 141 386
Beef 153 401
Beef 190 645
Beef 157 440
Beef 131 317
Beef 149 319
Beef 135 298
Beef 132 253
Meat 173 458
Meat 191 506
Meat 182 473
Meat 190 545
Meat 172 496
Meat 147 360
Meat 146 387
Meat 139 386
Meat 175 507
Meat 136 393
Meat 179 405
Meat 153 372
Meat 107 144
Meat 195 511
Meat 135 405
Meat 140 428
Meat 138 339
Poultry 129 430
Poultry 132 375
Poultry 102 396
Poultry 106 383
Poultry 94 387
Poultry 102 542
Poultry 87 359
Poultry 99 357
Poultry 107 528
Poultry 113 513
Poultry 135 426
Poultry 142 513
Poultry 86 358
Poultry 143 581
Poultry 152 588
Poultry 146 522
Poultry 144 545

Mike White
02-25-2009, 08:02 AM
You need to set the field separator to a single space and make sure that the path and file name are correct. Also remember to replace \ with either \\ or /
Alternatively, you can use file.choose() instead of the file name to allow you to navigate to the file you want.
The following should work if you have just one space between each field in the text file

hotdogs<-read.table("c:\\temp\\hotdogs.txt", header=T, sep=" ")

hotdogs<-read.table(file.choose(), header=T, sep=" ")