Reputation: 7895
My data frame is breaking when i extract some rows from a factor column:
data.df = data.frame(x = factor(letters[1:10]))
data.temp = data.df[1:3, ]
print(data.temp)
How can i avoid that? I need to column name to be kept also. Thanks!
Upvotes: 1
Views: 1288
Reputation: 98439
You can add argument drop=FALSE
to keep data as data frame.
data.df = data.frame(x = factor(letters[1:10]))
data.temp = data.df[1:3, ,drop=FALSE]
print(data.temp)
x
1 a
2 b
3 c
Upvotes: 4