作者huangsam (sam)
看板R_Language
标题[问题] gsub
时间Tue Aug 30 18:52:34 2016
[问题类型]:
程式谘询
[问题叙述]:
想要使用gsub 把"-"取代成"/",若是单纯想要取代成"/"该如何写!谢谢
[程式范例]:
> gsub("\\-", "\\\\", "2016-07-16 17:11:07")
[1] "2016\\07\\16 17:11:07"
> gsub("\\-", "\\\", "2016-07-16 17:11:07")
Error: unexpected numeric constant in "gsub("\\-", "\\\", "2016"
[关键字]:
gsub
选择性,也许未来有用
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.51.170.56
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1472554356.A.4B7.html
1F:→ Wush978: escape character 08/30 19:00
2F:→ HeroNoah: or use exact matching: fixed = TRUE 08/30 20:25
3F:推 Edster: gsub("\\-", "\\'\'", "2016-07-16 17:11:07") 08/30 23:17
4F:推 Edster: 更正 gsub("\\'-'", "\\'\'", "2016-07-16 17:11:07") 08/30 23:21
5F:→ Edster: 但strftime 接 strptime 在时间资料格式转换比较常用吧 08/30 23:23
6F:→ huangsam: gsub("\\'-'", "\\'\'", "2016-07-16 17:11:07") 无法耶 09/02 16:43
7F:→ cywhale: gsub("-", "\\/", "2016-07-16 17:11:07") 09/02 21:10