Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

dataframe - Row names to column and modify dates in R

how can i modify the names to date format and put them in a column as dates?

names(df)     
      [6] "X1.23.20"       "X1.24.20"       "X1.25.20"       "X1.26.20"       "X1.27.20"      
     [11] "X1.28.20"       "X1.29.20"       "X1.30.20"       "X1.31.20"       "X02.01.2020"   
     [16] "X02.02.2020"    "X02.03.2020"    "X02.04.2020"    "X02.05.2020"    "X02.06.2020"   
     [21] "X02.07.2020"    "X02.08.2020"    "X02.09.2020"    "X02.10.2020"    "X02.11.2020"   
     [26] "X02.12.2020"    "X2.13.20"       "X2.14.20"       "X2.15.20"       "X2.16.20"      
     [31] "X2.17.20"       "X2.18.20"       "X2.19.20"       "X2.20.20"       "X2.21.20"      
     [36] "X2.22.20"       "X2.23.20"       "X2.24.20"       "X2.25.20"       "X2.26.20"      
question from:https://stackoverflow.com/questions/66054053/row-names-to-column-and-modify-dates-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use as.Date with specified format, e.g.,

> as.Date(v,"X%m.%d.%y")
[1] "2020-01-23" "2020-01-24" "2020-02-02" "2020-02-03"

data

v <- c("X1.23.20","X1.24.20","X02.02.2020","X02.03.2020") 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...