将mmm转换为R中的数字 [英] convert mmm to numeric in R

查看:113
本文介绍了将mmm转换为R中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经给出了一个名为month的列作为char变量的csv,其中包含月份的前三个字母。例如。 Jan,Feb,Mar,...Dec。

I have been given a csv with a column called month as a char variable with the first three letters of the month. E.g. "Jan", "Feb","Mar",..."Dec".

有没有办法将其转换为月份的数字表示,到12,甚至是日期格式的类型?

Is there any way to convert this to a numeric representation of the month, 1 to 12, or even a type that is in a date format?

谢谢。

推荐答案

使用匹配和预定义向量 month.abb

tst <- c("Jan","Mar","Dec")
match(tst,month.abb)
[1]  1  3 12

这篇关于将mmm转换为R中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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