Output function Cat,sink,writelines,write.table of R language

Source: Internet
Author: User

Output to the screen and output to a file according to the direction of the output.

The 1.cat function can be output to the screen or output to a file.

How to use: Cat (..., file = "", Sep = "", fill = false, labels = Null,append = False)

When there is a file, output to file. When there is no file, output to the screen.

Append parameter: Boolean value. True, the output is appended to the end of the file. FALSE to overwrite the original contents of the file.

Cat ("Hello") hellocat ("Hello", file= "D:/test.txt", append=t)

  

The 2.sink function redirects output results to a file.

How to use: sink (file = NULL, append = false, type = C ("Output", "message"),split = False)

Append parameter: Boolean value. True, the output is appended to the end of the file. FALSE to overwrite the original contents of the file.

Sink ("Hello.txt") # Redirects output to Hello.txtcat ("Hello") sink () # End redirect

 

The 3.writeLines function outputs a string vector to a file (overwriting the original content)

How to use: Writelines (text, con = stdout (), Sep = "\ n", usebytes = FALSE)

Text: string vector; Con: output file

A=c ("one","tew") writelines (A,con="  D:/test.txt", sep="\ t")

Problem: The original content is overwritten each time it is called?

The 4.write.table () function outputs the contents of the Dataframe to a file.

Usage:write.table (x, File = "", append = FALSE, quote = TRUE, Sep = "",eol = "\ n", na = "na", Dec = ".", Row.) Names = True,Col.names = true, Qmethod = C ("Escape", "double"),fileencoding = "")

M=matrix (1:12,nrow=3) df=as.data.frame (m) write.table (df,file= "D:/test.txt", append=t,row.names=f)

  

Output function Cat,sink,writelines,write.table of R language

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.