Re: [R] "And" condition spanning over multiple columns in data frame

2024-09-12 Thread Rui Barradas
Às 08:42 de 12/09/2024, Francesca escreveu: Dear contributors, I need to create a set of columns, based on conditions of a dataframe as follows. I have managed to do the trick for one column, but I do not seem to find any good example where the condition is extended to all the dataframe. I have

Re: [R] "And" condition spanning over multiple columns in data frame

2024-09-12 Thread Eric Berger
Hi, To rephrase what you are trying to do, you want a copy of all the cp columns, in which all the NAs become 1s and any other value becomes a zero. There is an exception for the first row, where the NAs should become 0s. a <- c10Dt b <- matrix(as.numeric(is.na(a[,-1])), nrow=nrow(a)) b[1,] <- 0

Re: [R] "And" condition spanning over multiple columns in data frame

2024-09-12 Thread Ivan Krylov via R-help
В Thu, 12 Sep 2024 09:42:57 +0200 Francesca пишет: > c10Dt <- mutate(c10Dt, exit1= ifelse(is.na(cp1) & id!=1, 1, 0)) > So, I create a new variable, called exit1, in which the program > selects cp1, checks if it is NA, and if it is NA but also the value > of the column "id" is not 1, then it giv

[R] "And" condition spanning over multiple columns in data frame

2024-09-12 Thread Francesca
Dear contributors, I need to create a set of columns, based on conditions of a dataframe as follows. I have managed to do the trick for one column, but I do not seem to find any good example where the condition is extended to all the dataframe. I have these dataframe called c10Dt: id cp1 cp2 cp