将数据帧转换为矢量 [英] Convert data frame into vector
本文介绍了将数据帧转换为矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个单行/列 dataframe
,我想将其转换为一个值.
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
我已经做到了这一点:
b <- as.list(df)[[1]]
># [1] 300
以使 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?
推荐答案
基本上,数据帧是列表,因此您可以调用 unlist(df)
.
Basically, data frames are lists, so that you can invoke unlist(df)
.
这篇关于将数据帧转换为矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文