[R] How to read a file of the following format?
David Winsemius
dwinsemius at comcast.net
Wed Mar 17 03:50:14 CET 2010
On Mar 16, 2010, at 10:29 PM, rosemary roy wrote:
> Hi all
>
> I have a data set of the following format.
>
> 0 0.7087872E+06
> 5 0.7087872E+06
> 10 0.7087872E+06
> 15 0.7087872E+06
> 20 0.7087872E+06
> 25 0.7087872E+06
> 30 0.7087872E+06
> 35 0.7087872E+06
>
> I was trying to read in this file and plot it.
>
> leg16<-read.csv("wwleg16.ttn",sep=" ", dec=".", header =F)
Why would you use read.csv when the file is not comma-separated? If
you get nothing it is probably because you have not put the file in
your working directory.
This is what I get (because of every space is interpreted as a
separator.)
> leg16<-read.csv("ttest.tnn",sep=" ", dec=".", header =F)
> leg16
V1 V2 V3 V4 V5 V6 V7 V8
1 NA NA NA NA NA 0 NA 708787.2
2 NA NA NA NA NA 5 NA 708787.2
3 NA NA NA NA 10 NA 708787.2 NA
4 NA NA NA NA 15 NA 708787.2 NA
5 NA NA NA NA 20 NA 708787.2 NA
6 NA NA NA NA 25 NA 708787.2 NA
7 NA NA NA NA 30 NA 708787.2 NA
8 NA NA NA NA 35 NA 708787.2 NA
Use read.table instead. (and it will only read it if if is in your
working directory.)
> leg16<-read.table("ttest.tnn", dec=".", header =F)
> leg16
V1 V2
1 0 708787.2
2 5 708787.2
3 10 708787.2
4 15 708787.2
5 20 708787.2
6 25 708787.2
7 30 708787.2
8 35 708787.2
>
> But leg16 holds all NA's.
>
> How can I read this properly as two numeric values?
>
> I can do this in Excel, but want to learn to do in R also. Could
> anyone
> of you help me with this?
>
> Regards
>
> Rose
>
> [[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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list