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.
请帮忙。谢谢。
1 个解决方案
#1
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.
这将避免任何可能重新分配“合并”名称。
#1
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.
这将避免任何可能重新分配“合并”名称。