【问题标题】:Replace the date value on one cell in R替换R中一个单元格上的日期值
【发布时间】:2021-07-29 18:32:10
【问题描述】:

我会替换单个单元格中的日期值,但我没有找到方法...

## dataframe = these_ac
## Anonymat = one of the variables
## these_ac$Anonymat == 17725 : the ligne I want to select
## entree = a date variable

these_ac[these_ac$Anonymat == 17725, "entree"] <- 1993-03-22 

【问题讨论】:

  • (1) 1993-03-22 不是日期,它是解析为 1968 的算术表达式,您可能希望引用它,可能更多:"1993-03-22"as.Date("1993-03-22")。 (2)如果你想替换它Anonymat == 17725,那为什么你的条件Anonymat == 1
  • t 如果您创建一个小的可重复示例以及预期的输出,那么会更容易提供帮助。阅读how to give a reproducible example
  • 谢谢Ronak,下次我会这样做
  • r2evans,这个错误我已经改正了,解决方法是:these_ac[these_ac$Anonymat == 17725, "entre"]

标签: r date select replace


【解决方案1】:

these_ac["entree"][these_ac["Anonymat"] == 17725] &lt;- "22/03/1993"

我认为这是一种方法。

它适用于我的情况。

【讨论】:

    猜你喜欢
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 2020-12-15
    相关资源
    最近更新 更多