Subscription in Data Frame is returning vectors instead of factors!

According to R specification when we perform subscription on data frames defined by data.frame( ... ) e.g. df[1, 2] the printed value should be a FACTOR, however, in my case, it's printing normal vector. What could have gone wrong?

my.dataset <- data.frame(site = c('A', 'B', 'A', 'A', 'B', 'B'), 

season = c('Winter', 'Summer', 'Summer', 

'Spring', 'Fall', 'Spring'),

pH = c(7.4, 6.3, 8.6, 7.2, 8.9, 8.4))

When I print:

my.dataset[1,2]
[1] "Winter"

Why printed out a vector not a factor?

In R version 4 the stringsAsFactors default for data.frame was set to FALSE rather than TRUE

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.