Displaying 3 results from an estimated 3 matches for "unknowntona".
2007 Feb 07
6
setting a number of values to NA over a data.frame.
This is probably a simple problem but I don't see a
solution.
I have a data.frame with a number of columns where I
would like 0 <- NA
thus I have df1[,144:157] <- NA if df1[, 144: 157] ==0
and df1[, 190:198] <- NA if df1[, 190:198] ==0
but I cannot figure out a way do this.
cata <- c( 1,1,6,1,1,NA)
catb <- c( 1,2,3,4,5,6)
doga <- c(3,5,3,6,4, 0)
dogb <- c(2,4,6,8,10,
2013 Apr 25
1
Assigning a variable value based on multiple columns
Hi All,
I'm hoping someone can help me with a relatively simple problem. Take the following dataset:
ID Diabetes ESRD HIV Contact
1 0 0 NA 0
2 1 0 NA 0
3 NA 1 0 0
4 0 NA 0 1
5 1 1 1 0
I want to generate a
2007 Nov 22
1
Summary: Process multiple columns of data.frame
Thank you Jim Holtman and Mark Leeds for your help.
Original question:
>How do I do the following more concisely?
> Bout[is.na(Bout$bd.n), 'bd.n'] <- 0
> Bout[is.na(Bout$ht.n), 'ht.n'] <- 0
> Bout[is.na(Bout$dbh.n), 'dbh.n'] <- 0
>. . .
Solution:
for (i in c('bd.n', 'ht.n', 'dbh.n')) Bout[is.na(Bout[[i]]), i] <- 0
Toy