On 06/03/2013 12:57 PM, jsdroyster wrote:> Hello kind and R-knowledgeable souls!
>
> I am trying to use read.fortran to read in old datasets in 80-column-card
format
> with no separators between variables (just 80 columns of solid digits).
> I comprehend the instructions for specifying the columns for each variable,
but
> I can't understand how to assign the variable names after reading the
help pages
> for read.fortran, read.fwf and read.table.
>
> I tried putting a col.names section in the read.fortran statement:
>
> AN35
<-data.frame(read.fortran(filename,c("I9","4I2","2I1","3I2","I1","16I2",
> "I1","I5","I1","I3","I2",
"A4","3A1","A2","A1"),
> header = FALSE,skip=0,sep="@",
> col.names >
paste(idno,empmo,empyr,birthmo,birthyr,sex,race,teno,testmo,testyr,
>
testtyp,L500,L1k,L2k,L3k,L4k,L6k,L8k,RT1k,R500,R1k,R2k,R3k,R4k,R6k,R8k,
> HPD,dept,shift,TWA,envclas,jobcode,hobby.med.STS,audclas,disp),
The paste() call will try to find variables with those names, and
concatenate their contents. That's not what you want. You want
something like
col.names = c("idno", "empmo", ....)
> row.names = (idno) ))
>
>
> I also tried a separate dimnames statement like so:
>
> dimnames(AN35)[[2]] <-
>
c("idno","empmo","empyr","birthmo","birthyr","sex","race",
>
>
"teno","testmo","testyr","testtyp","L500","L1k","L2k","L3k","L4k","L6k","L8k","RT1k",
>
>
"R500","R1k","R2k","R3k","R4k","R6k","R8k","HPD","dept","shift","TWA",
>
"envclas","jobcode","hobby","med","STS","audclas","disp")
>
>
> I copied this from some documentation but I have no clue what the [[2]]
means.
dimnames() is a function that returns a list of row names and column
names. The column names are the second component, so
dimnames(AN35)[[2]] <- something
changes the column names.
Duncan Murdoch>
> If anyone has one good example that would help me a lot!
> Thanks in advance!
> Julie
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.