Jon Williams Jon Williams - 3 months ago 7
R Question

Any ideas on why my vector is null in R?

I pull a csv into df_spot with no headers, then check the data:

> df_spot$V3 [1] 43.86757 43.86764 43.86761 43.86764 43.86760 43.86761
> df_spot$V4 [1] -108.9588 -108.9588 -108.9588 -108.9588 -108.9588 -108.9588
> df_spot$V5 [1] 8/12/2016 8/12/2016 8/12/2016 8/12/2016 8/12/2016 8/12/2016 Levels: 8/12/2016
> df_spot$V6

[1] 5:40 PM 5:35 PM 5:30 PM 5:25 PM 5:12 PM 5:11 PM
Levels: 5:11 PM 5:12 PM 5:25 PM 5:30 PM 5:35 PM 5:40 PM


All's good! So now I try to add those 4 into a vector:

> tracker_spot <- c(df_spot$v3,df_spot$v4,df_spot$v5,df_spot$v6)
> tracker_spot


NULL

Uhh, how did it become NULL???

> mode(df_spot$V3)
[1] "numeric"
> mode(df_spot$V4)
[1] "numeric"
> mode(df_spot$V5)
[1] "numeric"
> mode(df_spot$V6)
[1] "numeric"


I check mode's and all are numeric, any ideas??

Thanks in advance!

Answer

R is case sensitive. If your vector is called, e.g., df_spot$V3 with capital V you cannot expect to obtain a useful result with df_spot$v3 (with lower case V).

So instead of

tracker_spot <- c(df_spot$v3,df_spot$v4,df_spot$v5,df_spot$v6)

try first with

tracker_spot <- c(df_spot$V3,df_spot$V4,df_spot$V5,df_spot$V6)

Then, if the result is still not what you expect, the other answers and comments will probably guide you towards the solution of your problem.

Comments