Re: [R] merging two data sets with no column header

From: David Winsemius <>
Date: Tue, 03 Jun 2008 02:12:08 +0000 (UTC)

kayj <> wrote in

> I have two data sets data1 and data2 with no column names( No
> header). The first coluimn in both data sets represents the case ID.
> How can I tell R to merge the two data sets by the case ID if there
> is no header? Also, In data1 I have more cases and I would like the
> result of the merge to have all the cases in both data1 and data2.
> there may be some duplicate cases.

If you bring the data into a dataframe, default variable names will be assigned. merge would be the function to use but you will need to decide if its default behavior is satisfactory.

See whether these examples are illuminating:

vv <- data.frame(V1=1:10, V2=letters[1:10])

# read.table("data1.txt", header=FALSE)  would produce a data.frame 
# with # first variable, V1
# However, merge would use all the column names the are shared unless 
# told to not do so. So give the other columns different names:

vv2 <- data.frame(V1=5:14, V8=letters[5:14]) merge(vv,vv2)

# create a duplicate
vv[8,1] <- 7

David Winsemius

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 03 Jun 2008 - 02:47:52 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 Tue 03 Jun 2008 - 03:30:38 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive