[R] How to read in this data format?
Petr Klasterecky
klaster at karlin.mff.cuni.cz
Thu Mar 1 12:29:35 CET 2007
Well, not extremely elegant, but should work:
1) open your file in some ascii text editor, delete the rubbish at the
beginning up to line Scan 1, and replace all spaces in names - e.g. make
a mass replace of 'Retention Time' by let say 'RetentionTime'.
2) Use read.table(), matrix() and data.frame():
d <- read.table('yourfile')
dd <- matrix(as.numeric(t(d)[2,]),byrow=TRUE,nrow=HowManyScansYouHave)
dd <- data.frame(dd)
names(dd) <- d[[1]][1:HowManyObservationsYouHavePerScan]
Petr
Bart Joosen napsal(a):
> Hi,
>
> I recieved an ascii file, containing following information:
>
> $$ Experiment Number:
> $$ Associated Data:
>
> FUNCTION 1
>
> Scan 1
> Retention Time 0.017
>
> 399.8112 184
> 399.8742 0
> 399.9372 152
> ....
>
> Scan 2
> Retention Time 0.021
>
> 399.8112 181
> 399.8742 1
> 399.9372 153
> .....
>
>
> I would like to import this data in R into a dataframe, where there is a
> column time, the first numbers as column names, and the second numbers as
> data in the dataframe:
>
> Time 399.8112 399.8742 399.9372
> 0.017 184 0 152
> 0.021 181 1 153
>
> I did take a look at the read.table, read.delim, scan, ... But I 've no idea
> about how to solve this problem.
>
> Anyone?
>
>
> Thanks
>
> Bart
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic
More information about the R-help
mailing list