[R] Importing fixed-width data

From: James Rome <jamesrome_at_gmail.com>
Date: Wed, 25 May 2011 11:42:37 -0400

I have a data set where the lines look like: 2011-05-13 00:00:00 EONAAL330 dfa13002516PSCNONA 2011-05-13 00:00:01 EONAAL223 laa13044510AS.NONM Some lines are missing the field before and after the NON: 2011-05-13 00:00:05 EONBHS229 mia13001621NON

I read them into R using

    df = read.fwf(file, widths=c(19,-4,7,3,8,2,1,3,1),        



The documentation for read.fwf says that the data are read into a dataframe. Yet, I get a list, and the conversions I specified do not seem to have been obeyed:
> df[1:20,]

                         DateTime  Flight Dest  ArrTime MsgType Conf
Runway Source
1  2011-05-13 00:00:00 AAL330   dfa 13002516      PS    C    NON      A
2  2011-05-13 00:00:01 AAL223   laa 13044510      AS    .    NON      M
. . .
> sapply(df, mode)

   DateTime Flight Dest ArrTime MsgType Conf   "numeric" "numeric" "numeric" "numeric" "character" "numeric"

     Runway Source
  "numeric" "numeric"
> dfn = df[!is.na(df$Source),]
> mode(df)

[1] "list"

What am I doing wrong?

Jim Rome

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 25 May 2011 - 15:44:36 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 25 May 2011 - 19:20:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive