I used the readxl
package to import from the Excel file into RStudio. Now I'm trying to access a column in that dataset using the $
operator. However, I keep getting the notification:
(Type Error): null is not an object (evaluating a.length)
Even though I've performed this type of operation many times before without issue...
The error I'm getting:
The dataset in the Global Environment pane:
The root of the problem is located in NA
used as a column name. The error is thrown since RStudio autocompletion is not able to extract column names.
Please see the reproduction of the problem:
df <- data.frame(a = 1:3, b = 1:3)
names(df)[2] <- NA
If you will try to typedf$a
the error below will be generated.
To avoid this kind of situation you should assign data.frame
column names explicitly. You have to options:
assign names(df) <- c("a", "b")
;
delete the spacer columns from the source Excel file to avoid NA
use as the column names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With