更改数据框的列类型 [英] Change the column type of data frame

查看:173
本文介绍了更改数据框的列类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大量数值的数据框。数据框如下

 > datedPf 
日期代码数量
96828 2013-01-11 ABT 700
96829 2013-01-11 AMD 9600
96830 2013-01-11 AMG 600
96831 2013 -01-11 AGCO 800
96832 2013-01-11 A 1300
etc ....

代码和数量列的类型是因子。我发现使用 class(datedPf $ ticker) class(datedPf $ quantity)分别。但是,日期列的类型是 date 。我想将该类型更改为 factor 。我如何改变这个?

解决方案

datedPf $ date = as.factor(datePf $ date) / code>但是你确定这是你想要做的吗?


I have a data frame containing huge amount of values. The data frame is as follows

> datedPf
            date ticker quantity
96828 2013-01-11    ABT      700
96829 2013-01-11    AMD     9600
96830 2013-01-11    AMG      600
96831 2013-01-11   AGCO      800
96832 2013-01-11      A     1300
etc....

The type of the "ticker" and "quantity" columns are factor. I found this using class(datedPf$ticker) and class(datedPf$quantity) respectively. But the type of the "date" column is date. I want to change that type to factor. How can i change this?

解决方案

datedPf$date = as.factor(datePf$date) but are you sure that it is what you want to do ?

这篇关于更改数据框的列类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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