I have a .txt file and am using Rstudio.
200416657210340 1665721 20040608 20090930 20060910 20070910 20080827 20090804
200416657210345 1665721 20040907 20090203 20070331 20080719
200416657210347 1665721 20040914 20091026 20070213 20080114 20090302
200416657210352 1665721 20041111 20100315 20070123 20071205 20081202
I am trying to read in the .txt file using read.fwf :
gripalisti <- read.fwf(file = "gripalisti.txt",
widths = c(15,8,9,9,9,9,9,9),
header = FALSE,
#stringsAsFactors = FALSE,
col.names = c("einst","bu","faeding","forgun","burdur1",
"burdur2","burdur3","burdur4"))
This works and the columns are the correct lenght. However the "einst" and "bu" are supposed to be integer values and the rest are supposed to be dates.
When imported all the values in the first column (ID variables) look like this:
2.003140e+14
I have been trying to search for a way to change the imported column to integer (or character?) values and I have not found anything that does not result in an error. An example, that I tried after a google:
gripalisti <- read.fwf(file = "gripalisti.txt",
widths = c(15,8,9,9,9,9,9,9),
header = FALSE,
#stringsAsFactors = FALSE,
col.names = c("einst","bu","faeding","forgun","burdur1",
"burdur2","burdur3","burdur4"),
colclasses = c("integer", "integer", "Date", "Date",
"Date", "Date", "Date", "Date"))
results in the error:
Error in read.table(file = FILE, header = header, sep = sep, row.names = row.names, :
unused argument (colclasses = c("integer", "integer", "Date", "Date", "Date", "Date", "Date", "Date"))
There are many missing values in the dataset that is over 100.000 lines. So other ways of importing have not worked for me. The dataset is NOT tab delimited.
Sorry if this is obvious, I am a very new R user.
edit:
Thanks for the help, I changed it to:
colClasses = c("character",
And now it look good.
As suggested in the comments:
colClasses=
, notcolclasses=
, typo;"integer"
, it must either be"numeric"
or"character"
;%Y-%m-%d
, you will need to convert them after reading in the data.Prep:
Execution: