Re: [R] Bizarre - R crashes on merge

From: Philipp Pagel <p.pagel_at_wzw.tum.de>
Date: Wed, 30 Jul 2008 12:24:22 +0200

> I have a large data.frame, 1530 observation with 6 columns. I want to
> merge a 7th column, a transformation of the response variable (hospital
> admissions), namely
> trans<-sqrt(copd$admissions+0.25)
> trans<-data.frame(trans)
> And now when I do
> copd2<-merge(copd,trans)
> (copd being my original data.frame), R either crashes or is taking an
> extremely long time to do the computation. I had expected the
> computation to be done almost instantly as I have done similar things in
> R recently, however my system becomes very slow to the point of being
> unusable.

If I understand correctly, all you want to do is add another column to your data.frame. Unless I have overlooked something, a simple assignement should do:

copd$trans <- copd$admissions+0.25

The reason your computation takes long/crashes is that you are merging two data frames which have no common columns to merge on. So merge() is generating all possible combinations for you.

> a = data.frame(1:3)
> b = data.frame(4:6)
> merge(a,b)
  X1.3 X4.6
1 1 4
2 2 4
3 3 4
4 1 5
5 2 5
6 3 5
7 1 6
8 2 6
9 3 6

This is most likely not what you intended. I guess you were looking for cbind() rather than merge()

cu

        Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

______________________________________________
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 Wed 30 Jul 2008 - 10:29:25 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 Wed 30 Jul 2008 - 11:32:59 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