Re: [R] problems with reading the data and merge

From: Daniel Folkinshteyn <dfolkins_at_gmail.com>
Date: Fri, 06 Jun 2008 00:17:59 -0400

the '00' entries may be in a numeric column, so it gets typecast to a number, and of course 00 == 0, numerically speaking, so they get 'condensed'.

to be sure you read everything "as is", specify "colClasses='character'. : data<-read.table("data.txt",sep='\t', header=T, colClasses='character') will read all data in character form, and no truncation of initial zeros will take place in even all-numeric columns.

when you read in with "header=F", what happens is that column names (which are probably letters rather than numbers), become part of the column, and then the column is not all numeric, and is thus typecast to a factor, rather than to numeric, and thus the 00's are preserved.

hope that clarifies things. (and you can always see ?read.table for more detailed explanations)

on 06/05/2008 07:58 PM kayj said the following:
> I have a problem with reading a file data.txt that has a header
> Each row has the individual ID and then some data that are letter and
> numbers such as 00
> If I read the file as
>
> data<-read.table("data.txt",sep='\t', header=T)
> write.table(data,file="data1.txt", sep='\t', quote=F, col.names=T,
> row.names=F)
>
> data1.txt looks different than data.txt. In data1.txt some of the 00 entries
> are replaced with just a 0!
>
> But If I read the file as
> data<-read.table("data.txt",sep='\t', header=F)
> write.table(data,file="data2.txt", sep='\t', quote=F, col.names=F,
> row.names=F)
>
> Then data2.txt looks exactly like data.txt (no problem)
>
> My problem is when I need to merge data with another data set for example
> data3,
> How can I telll R to merge them If I specify the header=F,
> I tried
>
> M<-merge(data, data3, by”V1”) This does not work.
>
> What is the problem? I hope someone can help
>
>



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. Received on Fri 06 Jun 2008 - 06:24:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 06 Jun 2008 - 06:30:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive