Entering edit mode
6.0 years ago
wkmustahs21
▴
30
Hi
I am having an issue with assigning factors to my data CSV. Here is a summary of the data frame:
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 ...
But I get this error:
HAYSData$Rep<-as.factor(HAYSData$Rep)
Error in $<-.data.frame(*tmp*, Rep, value = integer(0)) :
replacement has 0 rows, data has 303
I get the same type of error for Entry, Range, and Rows. I am not sure when I look at length(Entry) for example I get 300. I even tested with changing "as.factor" to "as.numeric" but it does not help.
I don't have an "na" in my data each category is its own column as well.
I don't know if something is wrong with my CSV. I have worked this same script with another CSV but no issues in the part of the script for the other data.
Can someone please help me?
Can you show the entire output of, for example,
HAYSData$Rep
andas.factor(HAYSData$Rep)
? Paste them here and wrap with the code buttonHi
So I did it two ways:
then I wrote it as in the script:
This is what I have when I write "as.factor(HAYSData$REP)"
For just "as.factor(HAYSData$Rep) :
One thing I notice is that my headers in my CSV are in Caps Lock ...so could this be a reason of why R is not recognizing my headers correctly?
Yes, R is case sensitive. That looks like the issue.