[R] Data separated by spaces, getting data into R using field lengths

Duncan Murdoch murdoch at stats.uwo.ca
Tue Sep 8 13:59:13 CEST 2009


On 9/8/2009 7:53 AM, Lauri Nikkinen wrote:
> I have a text file similar to this (separated by spaces):
> 
> x <- "DF12 This is an example 1 This
> DF12 This is an 1232 This is
> DF14 This is 12334 This is an
> DF15 This 23 This is an example
> "
> 
> and I know the field lengths of each variable (there is 5 variables in
> this data set), which are:
> 
> varlength <- c(2, 2, 18, 5, 18)
> 
> How can I import this kind of data into R, using the varlength
> variable as an field separator indicator?

See ?read.fwf.

Duncan Murdoch




More information about the R-help mailing list