Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error during merge in R : Unused arguments

Tags:

merge

dataframe

r

I am trying to merge two dataframes as below. But this give me error in merge as below. I explored and could not figure out what is wrong in my code. Why this error is coming ? Sample Data, code and error are as below

dput(head(dataframe, 10))
structure(list(Year = c(1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 
1979L, 1979L, 1979L, 1979L), Days = 1:10, Months = structure(c(5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("April", "Aug", 
"Dec", "Feb", "Jan", "July", "June", "March", "May", "Nov", "Oct", 
"Sep"), class = "factor"), SWE = c(201, 200, 199, 198, 197, 196, 
194, 192, 191, 190), Date = structure(c(3287, 3288, 3289, 3290, 
3291, 3292, 3293, 3294, 3295, 3296), class = "Date")), .Names = c("Year", 
"Days", "Months", "SWE", "Date"), row.names = c(NA, 10L), class =    "data.frame")
str(dataframe)
dataframe <- dataframe[order(dataframe$Date),]
tsq<-data.frame(Date = seq((min(dataframe$Date)),(max(dataframe$Date)),    by="1 day"))
head(tsq)
tail(tsq)
mergedata<-merge(dataframe,tsq,by="Date", all=T)

The Error is

 Error in merge(dataframe, tsq, by = "Date", all = T) : 
 unused arguments (tsq, by = "Date", all = T)

Please help. Thank you.

like image 592
Cirrus Avatar asked Dec 14 '22 14:12

Cirrus


1 Answers

The base merge function definitely has those parameters. It sounds like you've accidentally created a "shadow" merge function that's masking the true merge function. You can confirm this by looking at

conflicts(detail=TRUE)

If merge is defined twice, it should show up under two different search paths like this..

$.GlobalEnv
[1] "merge"

$`package:methods`
[1] "body<-"    "kronecker"

$`package:base`
[1] "body<-"    "kronecker" "merge"

Here we can see "merge" under both "base" and also in the global environment. If you didn't intend to create one in your global environment, it is likely a mistake, you can remove it with

rm(merge, envir=globalenv())

Also, you can explicitly call the base version of the function with

mergedata <- base::merge(dataframe,tsq,by="Date", all=T)

which would avoid the any potential reassigning of the "merge" name.

like image 190
MrFlick Avatar answered Jan 09 '23 10:01

MrFlick