rowsums错误:' x'当列的列是数字时,必须是数字
我正在尝试计算数据框中四列的行总和。数据框是从ESRI ArcGIS服务器导入的,当我查看要总结的列的结构时,它们都定义为数字,但我仍然会收到错误'x'必须是数字。
library(sf)
library(dplyr)
STTH <- st_read("https://services.arcgis.com/xxxx/ArcGIS/rest/services/service_xxxx/FeatureServer/")
STTH$projectsum <- rowSums(STTH [,19:22], na.rm = TRUE)
我的数据帧看起来像这样的列19:22
base_st_funding | base_stlandowner_funding | base__section6 | base_partners |
---|---|---|---|
1200 | NA | 2100 | 800 |
1200 | 200 | 3200 | NA |
1200 NA 1200 | NA | NA | 210 |
1200 | 350 | NA NA NA NA | NA NA |
,当我致电STR(Stth)时,我可以为列19:22
$ base_st_st_funding: int 2950 NA NA NA 4905 NA 100 NA NA NA ...
$ base_stlandowner_funding : int 3300 NA NA NA 20981 NA NA NA NA NA ...
$ base_section6 : int NA NA NA NA 40364 NA NA NA NA NA ...
$ base_partners :int na na na na 25000 na na na na na ...
I'm trying to calculate the row sum for four columns in a dataframe. The dataframe was imported from an ESRI ArcGIS server and when I look at the structure of the columns I want to sum they all are defined as numeric but I still get the error 'x' must be numeric.
library(sf)
library(dplyr)
STTH <- st_read("https://services.arcgis.com/xxxx/ArcGIS/rest/services/service_xxxx/FeatureServer/")
STTH$projectsum <- rowSums(STTH [,19:22], na.rm = TRUE)
My dataframe looks like this for the columns 19:22
base_ST_funding | base_stlandowner_funding | base__section6 | base_partners |
---|---|---|---|
1200 | NA | 2100 | 800 |
1200 | 200 | 3200 | NA |
1200 | NA | NA | 210 |
1200 | 350 | NA | NA |
And when I call str(STTH) I get this for columns 19:22
$ base_ST_funding : int 2950 NA NA NA 4905 NA 100 NA NA NA ...
$ base_stlandowner_funding : int 3300 NA NA NA 20981 NA NA NA NA NA ...
$ base_section6 : int NA NA NA NA 40364 NA NA NA NA NA ...
$ base_partners : int NA NA NA NA 25000 NA NA NA NA NA ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为对象是
sf
以及data.frame
。当我们选择列时,几何列将自动选择。我们可以转换为data.frame
,选择列并获取rowsums
- 可复制示例
It is because the object is a
sf
as well asdata.frame
. When we select the columns, the geometry columns are automatically selected. We could convert todata.frame
, select the columns and get therowSums
-reproducible example