如何修复R中的“错误:位置1处的尺寸(1)不正确”?

时间:2019-04-24 12:45:06

标签: r dplyr

那是我的代码:

library(dplyr)
datanew <- Data %>% 
  group_by(UUID) %>% 
  arrange(-ShapeArea) %>% 
  slice(1)

write.csv(datanew, file = "example.csv")

R给我这个错误:

Error: incorrect size (1) at position 1, expecting : 23466

期望数是此数据集中存在的行数。

我已经将此代码与相似的数据集一起使用,并且运行良好。

我想念什么? 谢谢!

OBJECTID   Gv       Gh            R       UUID             BWF  SPE    BEZSPE NAM OFL BEZOFL ATP BEZATP HHO          DES Z
1       23          1             0     0 DESHPDHK0005Cv9I 1610 0              0          0          0 1000         
2       24          1             0     0 DESHPDHK0005Cv9O 1610 0              0          0          0 1000         
3       25          1             0     0 DESHPDHK0005Cv9U 1610 0              0          0          0 1000         
4       26          1             0     0 DESHPDHK0003OvuK 1205         Tank 1130 Was          0          0          0 4210         
5       27          1             0     0 DESHPDHK0003OvuL 1205         Tank 1130 Was          0          0          0 4210         
6       28          1             0     0 DESHPDHK0003OvuJ 1205         Tank 1130 Was          0          0          0 4210      

 KENN     BEZEICH                                    CRS          SNR       DPRIO B   PR Shape_Length Shape_Area
1 AX51009 AX_SBau                                    ETRS89_UTM32 13042031   290   1  3  1,205862998          0
2 AX51009 AX_SBau                                    ETRS89_UTM32 13042031   290   1  3  16,03426872         10
3 AX51009 AX_SBau                                    ETRS89_UTM32 13042031   290   1  3  5,967865683          2
4 AX51003         AX_VorSp                           ETRS89_UTM32     1305   300   1  3  6,567442635          1
5 AX51003         AX_VorSp                           ETRS89_UTM32     1305   300   1  3  8,642245233          4
6 AX51003         AX_VorSp                           ETRS89_UTM32     1305   300   1  3  34,67721359         30
> 

1 个答案:

答案 0 :(得分:0)

library(dplyr)

datanew <- Data
is.data.frame(datanew) 
#if this returns TRUE -> dataframe
#if returns FALSE
datanew <- as.data.frame(datanew)

datanew %>% 
   group_by(UUID) %>% 
   arrange(Shape_Area) %>% 
   slice(1)
write.csv(datanew, file = "example.csv")