簡體   English   中英

無法為R指定CSV列標題“ as.factor”-錯誤

[英]Unable to designate CSV column heads “as.factor” for R -Error

我在為數據CSV分配因子時遇到問題。 以下是數據框的摘要:

> data.frame':  303 obs. of  12 variables:
> PLOT                : int  19 177 54 114 41 48 142 134 160 267 ...
> RANGE               : int  2 12 4 8 3 4 10 9 11 18 ...
> ROW                 : int  4 12 9 9 11 3 7 14 10 12 ...
> REP                 : int  1 1 1 1 1 1 1 1 1 1 ...
> ENTRY               : Factor w/ 184 levels "","17_YMG_0293",..: 40 40 77 82 87 88 102 103 103 6 ...
> PLOT_ID             : Factor w/ 301 levels "","18_HZG_OvOv_001",..: 20 178 55 115 42 49 143 135 161 268 ...
> Shatter             : num  9 9 9 9 9 9 9 9 9 8 ...
> Chaff.Color         : Factor w/ 4 levels "","*Blank ones are segregating in color",..: 3 4 3 4 4 4 3 4 4 3 ...
> Heading_d.from.Jan.1: int  138 139 137 133 135 135 133 137 135 136 ...
> Height_cm           : int  74 73 77 76 74 79 78 73 76 70 ...
> Plot.weight..kg.    : num  0.26 0.18 0.19 0.14 0.33 0.19 0.13 0.11 0.24 0.18 ...

但是我得到這個錯誤:

HAYSData$Rep<-as.factor(HAYSData$Rep)
Error in `$<-.data.frame`(`*tmp*`, Rep, value = integer(0)) : 
replacement has 0 rows, data has 303

我在Entry,Range和Rows中遇到相同類型的錯誤。 我不確定例如在查看length(Entry)是否得到300。我什至測試了將系數更改為數值,但這無濟於事。

我的數據中沒有NA ,每個類別也是其自己的列。

我不知道CSV是否有問題。 我已經使用另一個CSV處理了相同的腳本,但是該腳本的其他數據部分沒有問題。

有人可以幫幫我嗎?

區分大小寫,請嘗試:

HAYSData$REP <- as.factor(HAYSData$REP)
HAYSData$ENTRY <- as.factor(HAYSData$ENTRY)
HAYSData$RANGE <- as.factor(HAYSData$RANGE)
HAYSData$ROW <- as.factor(HAYSData$ROW)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM