Read the contents of the. txt file in Rgui, using the function read.table ("Xxx.txt", head=true| FALSE); where Head=true represents the caption that contains the attribute, and Head=false represents the caption without the attribute. The following is an example of reading a file in Exam0203.txt.
Exam0203.txt
Name Sex Age Height Weight
Alice F 56.5 84.0 Becka F 65.3 98.0 Gail F 64.3 90.0
Karen F 12 56 .3 77.0
kathey f 59.8 84.5
Mary f 66.5 112.0
Sandy F one 51.3 50.5
Sharon F 62.5 112.5
Ta Mmy F 62.8 102.5
Alfred m 69.0 112.5
Duke m 63.5 84.0 Guido m 67.0 133.0
James M 12 5 7.3 83.0
Jeffrey m 62.5 84.0
John m 59.0 99.5
Philip m 72.0 150.0
Robert M 12 64.8 128.0
Thomas M 57.5 85.0
William M 15 66.5 112.0
Because the first line of the file is a property name, which is a. txt with a caption, Head=true. Then, write. R script file, as follows:
exam0203. R
SETWD ("g:\\myproject\\rdoc\\unit1")
RT <-read.table ("Exam0203.txt", head=true); RT
Lm.sol <-LM ( WEIGHT~HEIGHT,DATA=RT)
Summary (Lm.sol)
Place the. txt and. r files in the same directory, such as: G:\myProject\RDoc\Unit1, if placed in a different directory, the. R setwd ("x:\\") is modified as shown in figure (1):
Figure (1) place the. txt and. r files in the same directory
The effect is as follows: