From a csv file I loaded date into an R dataframe that looks like this:
> head(mydata)
row lengthArray sports num_runs percent_runs
1 0 4 [24, 18, 24, 18] 0 0
2 1 10 [2, 2, 2, 2, 2, 2, 2, 2, 2, 2] 0 0
3 2 4 [0, 0, 0, 0] 0 0
4 3 2 [0, 0] 0 0
5 4 2 [18, 18] 0 0
6 5 1 [0] 0 0
I can access and get the types for the integer data frames no problem, but I can't figure out how to access sports
:
> class(mydata[4,3])
[1] "factor"
> string_factor = mydata[1,3]
> string_factor
[1] [24, 18, 24, 18]
6378 Levels: [0] [0, 0] [0, 0, 0] [0, 0, 0, 0] ... [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
> class(string_factor)
[1] "factor"
> string_factor_numeric = as.numeric(string_factor)
> string_factor_numeric
[1] 5181
I guess the best R response would be "don't do this", but this is how the data is coming, so I am wondering how I can get those numbers out of the array so that I can use them.
I should also mention that this Convert data.frame columns from factors to characters gave no error message but had no effect, as the array column continued to be classed as factors.
UPDATE: from the comments, you can see this can get you somewhere:
mydata[,3] <- as.character(mydata[,3])
However this still does not get you to an array with individually accessible elements.