rename value for multiple rows based on other variable
Asked Answered
F

1

0

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 this

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

I get the error message "duplicate subscripts for columns". Whats wrong with my command?

I also tried

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

with no error but also no participant with these value appearing

Furfur answered 14/6, 2020 at 19:1 Comment(0)
B
0

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.

Baltic answered 14/6, 2020 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.