Friday, August 05, 2005

Reformating a text file table with R

Mirjana had trouble with data in a text file: A table in which each line represented a record was exported to a text file from some unfamiliar statistical program. The program had broken lines every 10 values in stead of every 73 (the actual record length). Excel would not allow her to correctly import this table. A peculiar oddity was that decimal points were comma's (Dutch notation), and this had to be retained. In R a new file was created as follows:
x = scan(file = file.choose(), dec = ",")
y = matrix(x, ncol = 73, byrow = TRUE)
write.table(y, file = file.choose(), row.names =
            FALSE, col.names = FALSE, dec = ",")

0 Comments:

Post a Comment

<< Home