Re: [R] Subscripting problem with is.na()

2016-06-24 Thread Bert Gunter
s_temp3 <- data.frame(cust_id, closed_mdm_num1, closed_sls_num1) >> > ds_temp3 >> > >> > ds_temp3$closed <- ds_temp$closed_mdm_num1 | ds_temp$closed_sls_num1 # >> > WRONG >> > >> > # 4th try >> > ds_temp4 <- ds_temp3 >>

Re: [R] Subscripting problem with is.na()

2016-06-24 Thread William Dunlap via R-help
; > > # Does not run due to not allowed NA in subscripts > > ds_temp4[is.na(ds_temp4$closed_mdm_num1), ds_temp4$closed_mdm_num1] <- 0 > > ds_temp4[is.na(ds_temp4$closed_sls_num1), ds_temp4$closed_sls_num1] <- 0 > > > > # 5th try > > ds_temp4$closed_md

Re: [R] Subscripting problem with is.na()

2016-06-24 Thread Bert Gunter
gt; ds_temp4[is.na(ds_temp4$closed_sls_num1), ds_temp4$closed_sls_num1] <- 0 > > # 5th try > ds_temp4$closed_mdm_num1 <- ifelse(is.na(ds_temp4$closed_mdm_num1), 1, 0) > ds_temp4$closed_sls_num1 <- ifelse(is.na(ds_temp4$closed_sls_num1), 1, 0) > ds_temp4 > > ds_temp4$closed

Re: [R] Subscripting problem with is.na()

2016-06-24 Thread MacQueen, Don
), ds_temp4$closed_sls_num1] <- 0 > ># 5th try >ds_temp4$closed_mdm_num1 <- ifelse(is.na(ds_temp4$closed_mdm_num1), 1, 0) >ds_temp4$closed_sls_num1 <- ifelse(is.na(ds_temp4$closed_sls_num1), 1, 0) >ds_temp4 > >ds_temp4$closed <- ifelse(ds_temp4$closed_mdm_num1 == 1

Re: [R] Subscripting problem with is.na()

2016-06-24 Thread David L Carlson
1 1A NA > 2 0b NA > 3 2 NA > > David C > > -Original Message- > From: Bert Gunter [mailto:bgunter.4...@gmail.com] > Sent: Thursday, June 23, 2016 1:48 PM > To: David L Carlson > Cc: Ivan Calandra; R Help > Subject: Re: [R] Subscripting problem w

Re: [R] Subscripting problem with is.na()

2016-06-24 Thread PIKAL Petr
On Behalf Of > g.maub...@gmx.de > Sent: Friday, June 24, 2016 9:15 AM > To: Bert Gunter <bgunter.4...@gmail.com> > Cc: R Help <r-help@r-project.org> > Subject: Re: [R] Subscripting problem with is.na() > > Hi Bert, > > many thanks for all your help and your comments. I

Re: [R] Subscripting problem with is.na()

2016-06-24 Thread G . Maubach
o do it? Kind regards Georg > Gesendet: Donnerstag, 23. Juni 2016 um 23:55 Uhr > Von: "Bert Gunter" <bgunter.4...@gmail.com> > An: "David L Carlson" <dcarl...@tamu.edu> > Cc: "R Help" <r-help@r-project.org> > Betreff: Re: [R]

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread Bert Gunter
gt; 3 2 NA > > David C > > -Original Message- > From: Bert Gunter [mailto:bgunter.4...@gmail.com] > Sent: Thursday, June 23, 2016 1:48 PM > To: David L Carlson > Cc: Ivan Calandra; R Help > Subject: Re: [R] Subscripting problem with is.na() > > Not in genera

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread David L Carlson
A David C -Original Message- From: Bert Gunter [mailto:bgunter.4...@gmail.com] Sent: Thursday, June 23, 2016 1:48 PM To: David L Carlson Cc: Ivan Calandra; R Help Subject: Re: [R] Subscripting problem with is.na() Not in general, David: e.g. > test <- data.frame(a=c(1,NA,2),

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread Bert Gunter
6 66 > 7 77 > 8 00 > 9 99 > 10 10 10 > > - > David L Carlson > Department of Anthropology > Texas A University > College Station, TX 77840-4352 > > -Original Message- > From: R-help

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread David L Carlson
Behalf Of Ivan Calandra Sent: Thursday, June 23, 2016 10:14 AM To: R Help Subject: Re: [R] Subscripting problem with is.na() Thank you Bert for this clarification. It is indeed an important point. Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - E

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread ruipbarradas
Hello, You could do ds_test[is.na(ds_test$var1), ] <- 0  # note the comma or, more generally, ds_test[] <- lapply(ds_test, function(x) {x[is.na(x)] <- 0; x}) Hope this helps, Rui Barradas   Citando g.maub...@weinwolf.de: > Hi All, > > I would like to recode my NAs to 0. Using a single

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread Ivan Calandra
Thank you Bert for this clarification. It is indeed an important point. Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr --

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread Bert Gunter
Sorry, Ivan, your statement is incorrect: "When you use a single bracket on a list with only one argument in between, then R extracts "elements", i.e. columns in the case of a data.frame. This explains your errors. " e.g. > ex <- data.frame(a = 1:3, b = letters[1:3]) > a <- 1:3 >

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread Ivan Calandra
My statement "Using a single bracket '[' on a data.frame does the same as for matrices: you need to specify rows and columns" was not correct. When you use a single bracket on a list with only one argument in between, then R extracts "elements", i.e. columns in the case of a data.frame. This

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread Ivan Calandra
Dear Georg, You need to learn a bit more about the subsetting methods, depending on the object structure you're trying to subset. More specifically, when you run this: ds_test[is.na(ds_test$var1)] you get this error: "Error in `[.data.frame`(ds_test, is.na(ds_test$var1)) : undefined columns

Re: [R] Subscripting problem with is.na()

2016-06-23 Thread Ista Zahn
Suggestion: figure out the correct extraction syntax first. One you do that replacement will be easy. See ?Extract for all the messy details. Best, Ista On Jun 23, 2016 10:00 AM, wrote: > Hi All, > > I would like to recode my NAs to 0. Using a single vector everything is

[R] Subscripting problem with is.na()

2016-06-23 Thread G . Maubach
Hi All, I would like to recode my NAs to 0. Using a single vector everything is fine. But if I use a data.frame things go wrong: -- cut -- var1 <- c(1:3, NA, 5:7, NA, 9:10) var2 <- c(1:3, NA, 5:7, NA, 9:10) ds_test <- data.frame(var1, var2) test <- var1 test[is.na(test)] <- 0 test # NA