On Sep 8, 2013, at 19:08 , Rhode Early CHARLES wrote: > Good morning > I am trying to read this file in R. > > Nome AK 2.5 15 Miami FL 6.75 > 18 Raleigh NC . 12 > > > This what the code is for SAS, I ma trying to di the same in R. > > Input more than one observation from each record; > DATA rainfall; > INFILE ’c:\MyRawData\Precipitation.dat’; > INPUT City $ State $ NormalRain MeanDaysRain @@; > RUN; > PROC PRINT DATA = rainfall; > TITLE ’Normal Total Precipitation and’; > TITLE2 ’Mean Days with Precipitation for July’; > RUN; > > Thanks. > ------A Dieu soit la Gloire--------
scan() is your friend here: > l <- + scan(text="Nome AK 2.5 15 Miami FL 6.75 + 18 Raleigh NC . 12 + ", what=list("","",0,0), multi.line=TRUE, na.strings=".") Read 3 records > l [[1]] [1] "Nome" "Miami" "Raleigh" [[2]] [1] "AK" "FL" "NC" [[3]] [1] 2.50 6.75 NA [[4]] [1] 15 18 12 > names(l) <- c("city","state","normalRain","meanDaysRain") > as.data.frame(l) city state normalRain meanDaysRain 1 Nome AK 2.50 15 2 Miami FL 6.75 18 3 Raleigh NC NA 12 > (or use a named list for the what= argument) -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-help@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.