March 20, 2018 at 8:33 pm
Comments posted to this topic are about the item Loading Data
March 21, 2018 at 7:22 pm
To load a FULL set of fixed width data I used the function read.fwf (), given in answer No. 3. The result is a data.frame as produced by read.table which is called internally.
It was enough to change the sep = " " argument to sep = "". If sep = "" (the default for read.table) the separator is 'white space', that is one or more spaces, tabs, newlines or carriage returns.
The internally called read.table function loads the header by the vector specified in the widths argument.
When I ran this code:ncaa2018.data <- read.fwf("input.csv", widths= c(8,15,15,17,9), header= TRUE, sep="")
print(ncaa2018.data)
I got this result:Executing the program....
$Rscript main.r
GameDate Visitor Home VisitorScore HomeScore
1 20180315 Oklahoma URI 78 53
2 20180315 WrightState Tennessee 47 73
3 20180315 NC-Greensboro Gonzaga 64 68
4 20180315 Pennsylvania Kansas 60 76
5 20180315 Iona Duke 67 89
Code according to the "correct" answer No. 1:ncaa2018.data <- read.fwf("input.csv", widths= c(8,15,15,17,9), skip=1)
print(ncaa2018.data)
gives this result:Executing the program....
$Rscript main.r
V1 V2 V3 V4 V5
1 20180315 Oklahoma URI 78 53
2 20180315 WrightState Tennessee 47 73
3 20180315 NC-Greensboro Gonzaga 64 68
4 20180315 Pennsylvania Kansas 60 76
5 20180315 Iona Duke 67 89
I had time, so I enjoyed it...:ermm:
Thanks for this interesting question Steve.
March 21, 2018 at 11:49 pm
Interesting question, thanks Steve
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
March 22, 2018 at 3:41 am
Oh, so tricky - but I got it right by testing out.
Still, it seemed inelegant, and I felt option 3 might be the intended right answer, as I did not fathom blanks are simply not an allowed option in the header line.
Point earned and lesson learned: R may be useful, but do not expect it to be elegant!
March 22, 2018 at 10:55 am
This was supposed to be a simple question, but my headers kept throwing this off. Not sure why. I didn't try sep="". I used a space, set delimiters, and more. It was more cumbersome than I'd like, but hope you learned something.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply