R language reads the contents of the TXT file

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.