m_fac1 | ds_temp$closed_sls_fac1 #
>> > WRONG
>> >
>> > # 3rd try
>> > closed_mdm_num1 <- as.numeric(closed_mdm) # OK
>> > closed_sls_num1 <- as.numeric(closed_sls) # OK
>> >
>> > ds_temp3 <- data.frame(cust_id, closed_md
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_mdm_num1 <- ifelse(is.na(ds_temp4
s_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$clos
_temp$closed_mdm_num1 | ds_temp$closed_sls_num1 #
>WRONG
>
># 4th try
>ds_temp4 <- ds_temp3
>ds_temp4
>
># 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_s
> 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 with i
Behalf Of
> g.maub...@gmx.de
> Sent: Friday, June 24, 2016 9:15 AM
> To: Bert Gunter
> Cc: R Help
> Subject: Re: [R] Subscripting problem with is.na()
>
> Hi Bert,
>
> many thanks for all your help and your comments. I learn at lot this way.
>
> My question was about is.n
ly:
> >
> >> test <- data.frame(a=c(1,NA,2), b = c("A","b",NA), c= rep(NA,3))
> >> sapply(test, class)
> > a b c
> > "numeric" "factor" "logical"
> >> num <- sapply(test, is
t; 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 general,
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),
7 77
> 8 00
> 9 99
> 10 10 10
>
> -
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
>
> -Original Message-
> From: R-help [mailto:r
t.org] On 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
GE
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 vecto
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
--
https://www.resea
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
> identical(ex[1
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
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 s
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
> fine.
>
> But if I us
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 rec
18 matches
Mail list logo