Colclasses comand is failing with "scan()expected 'a real', got..." 消息。

问题描述 投票:0回答:1

我使用的命令是 colClasses 为了消除mi数据的第一列,其结构如下所示

structure(list(Index = 1:2, ReV_d_NSW = c(1.63848278146629, 1.96212225666041
), ReV_w_NSW = c(1.55174457184073, 1.65272563839375), ReV_m_NSW = c(4.34772016761621, 
4.15948097574855), ReV_d_QLD = c(14.2254291883897, 4.87574796172026
), ReV_w_QLD = c(3.50271406691242, 4.03974428936572), ReV_m_QLD = c(5.4535110422488, 
5.54631480940927), ReV_d_SA = c(2.61247959826628, 2.01498355466139
), ReV_w_SA = c(4.87813313234942, 4.96643028278639), ReV_m_SA = c(41.7492218579029, 
37.2708283220627), ReV_d_VIC = c(2.25727329357861, 1.28806882634575
), ReV_w_VIC = c(1.87039487904359, 1.82783924013819), ReV_m_VIC = c(3.52033525482833, 
3.45527816625453), ReCov_d_QLD_NSW_IHS = c(1.68786257472571, 
2.58052571095539), ReCov_w_QLD_NSW_IHS = c(1.38612531296242, 
1.60839609139634), ReCov_m_QLD_NSW_IHS = c(2.73613034592598, 
2.75930759291875), ReCov_d_SA_NSW_IHS = c(1.7088683861727, 1.31971288544524
), ReCov_w_SA_NSW_IHS = c(1.8047616665054, 1.8128153217549), 
ReCov_m_SA_NSW_IHS = c(7.60966879511642, 6.95166311676005
), ReCov_d_SA_QLD_IHS = c(-0.0720227623032456, 0.760059821937523
), ReCov_w_SA_QLD_IHS = c(0.791040047251097, 0.761263712916208
), ReCov_m_SA_QLD_IHS = c(2.11624026123024, 2.155213015942
), ReCov_d_SA_VIC_IHS = c(2.09724583794473, 1.4391382108463
), ReCov_w_SA_VIC_IHS = c(2.13726831502919, 2.13155667698993
), ReCov_m_SA_VIC_IHS = c(3.58961750850964, 3.43135956237216
), ReCov_d_VIC_NSW_IHS = c(1.78708826144829, 1.19854834558529
), ReCov_w_VIC_NSW_IHS = c(1.60812350172191, 1.58626875609991
), ReCov_m_VIC_NSW_IHS = c(2.63711145226054, 2.57240610190681
), ReCov_d_VIC_QLD_IHS = c(0.292579158585562, 0.915440632016275
), ReCov_w_VIC_QLD_IHS = c(1.18309902338191, 1.1644274933346
), ReCov_m_VIC_QLD_IHS = c(2.43173424508862, 2.40678217973295
)), row.names = 1:2, class = "data.frame")

我的数据是一个.txt文件,我使用下面的代码来读取它并删除第一列。

path_IV_HAR_m2<-file.choose()
IV_HAR_m2<-read.csv(path_IV_HAR_m2, colClasses = c(NULL, rep("numeric", 30)), sep="")

的错误说。

Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
scan() expected 'a real', got '"1"'

如上图所示,1是第1列的第一个观测值。

r csv read.csv
1个回答
1
投票

我认为你应该使用 "NULL" 内的引号,而不是 NULL.

IV_HAR_m2<-read.csv(path_IV_HAR_m2, colClasses = c("NULL", rep("numeric", 30)), 
sep="")
© www.soinside.com 2019 - 2024. All rights reserved.