R language Learning Note 001--reading CSV format data

Source: Internet
Author: User

read CSV format data

Data source is Southwestern University Siyakin Teacher's course assignment

Method One: Read.csv () function

1 file.choose () 2 read.csv ("c:\\users\\administrator\\desktop\\astocks.csv",3           head=t,sep=','5
Results

file.choose (): reads the file so that we know the specific path to the file.

File parameter : path and filename, Windows uses a backslash \ \

head=t: This is the first line, T indicates that the file has a title, and the first row in the file is the column name. If head=f, the original file is not

Title, add a line v1,v2, ... As the first line of the file, that is, the column name. The Read.csv () function defaults to head=t.

sep= ",": Delimiter problem, here the selection of separators will affect the input of the referenced string.

nrows=200: The number of rows problem, indicating that the first 200 lines of the file are read.

stringsasfactors = False : Character data is automatically converted to a factor when read, prevents conversion to a factor, and the parameter stringsasfactors = False,

Prevents the conversion of any factor in the imported data.

method Two: Read.table () function

1 a<-read.table ('c:\\users\\administrator\\desktop\\astocks.csv',  2               head=t,sep=','5, stringsasfactors = FALSE) 3 A
1 a[1:3,1:3]

Results

Slices: Select the number of rows and columns (choose between 1 and 3 rows and 1 to 3 columns)

R language Learning Note 001--reading CSV format data

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.