Reputation: 13827
I have a one row/column dataframe
that I would like to convert into a value.
df <- data.table(x=c(300))
># x
># 1: 300
I've managed to do it by doing this:
b <- as.list(df)[[1]]
># [1] 300
so that identical(b, 300) == T
Is there a simpler way to achieve this? I understand this is a very simple question but I couldn't find a solution. Help?
Upvotes: 0
Views: 6479
Reputation: 4187
Instead of using unlist
, you can also simply do:
x <- df$x
the result is a normal vector with the values from x
:
> x
[1] 300
Upvotes: 1
Reputation: 1481
Basically, data frames are lists, so that you can invoke unlist(df)
.
Upvotes: 4