Skip to content
Back to formatted view

Raw Message

Message-ID: <BAY135-W44DBC1170BE8BAB14B2FD2886D0@phx.gbl>
Date: 2009-05-01T12:51:53Z
From: Steve Murray
Subject: Problems with 'valid columns' when using merge

Dear all,

I am trying to use 'merge' within a loop, however, I receive an error relating to the 'by' argument of the command, as follows:

> merge_year <- 1986
> 
> for (i in 1:10) { # Number of file pairs
+     assign(paste("merged_arunfek_", merge_year, sep=""), merge(x=paste("arunoff_",start_arunoff, sep=""), y=paste("fekete_", start_fekete, sep=""), by=c("Latitude", "Longitude"), sort=FALSE))
+     attach(paste("merged_arunfek_", merge_year))
+     merge_year = merge_year+1
+     }
Error in fix.by(by.x, x) : 'by' must specify valid column(s)


However, as far as I can tell, the column names (as stated in the above code) appear to be valid: 


> colnames(arun_1986)
[1] "Latitude"  "Longitude" "Sim_1986" 
> colnames(fekete_1986)
[1] "Latitude"  "Longitude" "X1986"


I'm trying to merge based on both the Latitude and Longitude column and have used by=c("name_x", "name_y") before without too many problems. Any suggestions would be gratefully received.

Many thanks,

Steve