I recently started taking R lectures and I'm currently working on scanning files. On a worksheet, one of my questions is like:
Read the file Table6.txt, check out the file first. Notice that the information is repeated, we only want the first non-repeated ones. Make sure to create only characters not factors this time around. Lastly, we don’t want the comments.
The file is called Table6.Txt
I managed to write the code that read the table properly, but the answer sheet has an extra part inside the scan function that says flush=TRUE
My code was like:
df <- read.table("Table6.txt",skip = 1,header = TRUE,row.names = "Name",nrow
= 7,comment.char = "@",stringsAsFactors = FALSE)
And the answer sheet shows
df <- read.table("Table6.txt",skip = 1,header = TRUE,row.names = "Name",nrow
= 7,flush = TRUE,comment.char = "@",stringsAsFactors = FALSE)
What does the flush function do here? The outputs on both codes give the same dataframe.
df <- read.table("Table6.txt",skip = 1,header = TRUE,row.names = "Name",nrow
= 7,flush = TRUE,comment.char = "@",stringsAsFactors = FALSE)
df
Age Height Weight Sex
Alex 25 177 57 F
Lilly 31 163 69 F
Mark 23 190 83 M
Oliver 52 179 75 M
Martha 76 163 70 F
Lucas 49 183 83 M
Caroline 26 164 53 F
df <- read.table("Table6.txt",skip = 1,header = TRUE,row.names = "Name",nrow
= 7,comment.char = "@",stringsAsFactors = FALSE)
df
Age Height Weight Sex
Alex 25 177 57 F
Lilly 31 163 69 F
Mark 23 190 83 M
Oliver 52 179 75 M
Martha 76 163 70 F
Lucas 49 183 83 M
Caroline 26 164 53 F