多个数据框列中的值合并成一个向量 [英] Values from multiple dataframe columns into one vector

查看:60
本文介绍了多个数据框列中的值合并成一个向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框 df ,其中有很多列,并说有100行.

I have a dataframe df that has many cols and say 100 rows.

如何从名称为"alpha","gamma"和"zeta"的列中获取所有级别值,并将其中的300个存储在单个向量中?

How do I take all the level values from the columns with names "alpha", "gamma" and "zeta" and store the 300 of them in a single vector?

推荐答案

我发现首先转换为矩阵可以更轻松地达到等级.

I've found that converting to a matrix first makes getting to levels a bit easier.

as.vector(as.matrix(df[,c("alpha", "gamma", "zeta")]))

当然,当您最初读取数据时,您可能只需完成 stringsAsFactors = FALSE .

Of course, you could have just done stringsAsFactors=FALSE when you read the data in initially.

这篇关于多个数据框列中的值合并成一个向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆