How to read and write files in R language
This article is a detailed introduction to "how to read and write files in R language". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to read and write files in R language" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.
In R, what if we want to read files from the outside world or write files to a specific path?
To read a file, we can use the read.table function; to write a file, we can use the write.table function.
Read.table(file, header = FALSE, sep = "", quote = "\"", dec = ". ", numerals = c("allow.loss", "warn.loss", "no.loss"), row.names, col.names, as.is = ! stringsAsFactors, na.strings = "NA", colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, fill = ! blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE, comment.char = "#", allowEscapes = FALSE, flush = FALSE, stringsAsFactors = default.stringsAsFactors(), fileEncoding = "", encoding = "unknown", text, skipNul = FALSE)
Each parameter has its own meaning, among which the more commonly used are header,sep, etc.
file is the name of the file we read;header, set to T or F, whether to define the first line as header;sep is to set the delimiter in the file. Let's look at an example:
mydata