使用R中的Dplyr包中的排列函数的错误消息

时间:2016-10-21 14:58:02

标签: r dplyr

我有一个数据集,我试图按其中一个变量的升序重新排列。我必须创建一个函数来提供成功完成的新变量的条目,但是当我试图安排它时,控制台会出现以下错误:

  

错误:大小不正确(1),期待:1515

我已尝试更改新列的制作方式,并尝试重新安排,但它再次出现同样的错误!

以下是我写的代码:

# Add a variable which gives the distance from the centre of leeds
# Begin by creating a function which will give the distance from the centre of leeds to location of accident

distance <- function(Grid.Ref..Easting, Grid.Ref..Northing, Centre.Easting = 429967, Centre.Northing = 434260){

  easting.difference <- abs(Centre.Easting - Grid.Ref..Easting)

  northing.difference <- abs(Centre.Northing - Grid.Ref..Northing)

  dif <- round(sqrt(easting.difference^2 + northing.difference^2),digits=2)

  return(dif)

}

# use this function to now create a new column which shows the distance of the accident from the cente of Leeds
accident4 <- mutate(accident3,

                    "Distance.from.centre.of.Leeds" = distance(Grid.Ref..Easting, Grid.Ref..Northing, Centre.Easting = 429967, Centre.Northing = 434260)
)

# arrange the data in order of distance from the centre of Leeds in ascending order

accident5 <- arrange(accident4, "Distance.from.centre.of.Leeds")

0 个答案:

没有答案