rename value for multiple rows based on other variable

前端 未结 1 1711
一整个雨季
一整个雨季 2020-12-22 07:33

I\'ve got a data frame with multiple rows for each participant. There is an error in some of their ids (for example, some are double). I wanted to assign them a new one like

相关标签:
1条回答
  • 2020-12-22 08:28

    The error duplicate subscripts for columns tells you here that you are trying to assign a value to a nonsensical part of dataframe. So you need to use dat$participant rather than only dat.

    Generally speaking, you can use this command:

    dat$participant[some condition] <- "101"
    

    E.g. modifying your first command:

    dat$participant[dat$participant == "36" & dat$date == "2020-06-07_12h33.46.880"] <- "101"
    

    But there can be another problem, e.g. make sure you provide correct date (copy and paste the value, as there are many types of hyphens and dashes) which can occur in dirty data, maybe the IDs are not characters but numbers, etc.

    So if you want more concrete help, provide here a few lines of your data frame.

    0 讨论(0)
提交回复
热议问题