My function and NA Values Problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

My function and NA Values Problem

Temel İspanyolca
Dear R Staff

My working file is in the annex. "g1.csv"
I have only 2 columns. Rice and coke.
I try to execute following(below) function, but do not work.
Because "Coke" value has NA values.
I try to add "na.rm=True" to the function but do not work
How can I solve this problem with this function or another algorithm?
(Note: I have normally 450 columns)

Sincerely
Engin YILMAZ


apply(g1, 2, function(c) sum(c==0))

Rice Coke
   0   NA
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: My function and NA Values Problem

Eric Berger
na.rm=TRUE  (you need to capitalize)


On Fri, Oct 27, 2017 at 10:43 AM, Engin YILMAZ <[hidden email]>
wrote:

> Dear R Staff
>
> My working file is in the annex. "g1.csv"
> I have only 2 columns. Rice and coke.
> I try to execute following(below) function, but do not work.
> Because "Coke" value has NA values.
> I try to add "na.rm=True" to the function but do not work
> How can I solve this problem with this function or another algorithm?
> (Note: I have normally 450 columns)
>
> Sincerely
> Engin YILMAZ
>
>
> apply(g1, 2, function(c) sum(c==0))
>
> Rice Coke
>    0   NA
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: My function and NA Values Problem

Ismail SEZEN
In reply to this post by Temel İspanyolca

> On 27 Oct 2017, at 10:43, Engin YILMAZ <[hidden email]> wrote:
>
> Dear R Staff
>
> My working file is in the annex. "g1.csv"
> I have only 2 columns. Rice and coke.
> I try to execute following(below) function, but do not work.
> Because "Coke" value has NA values.
> I try to add "na.rm=True" to the function but do not work
> How can I solve this problem with this function or another algorithm?
> (Note: I have normally 450 columns)
>
> Sincerely
> Engin YILMAZ
>
>
> apply(g1, 2, function(c) sum(c==0))
>
> Rice Coke
>   0   NA

A simple reproduciple example always works,

# create sample data
df <- data.frame(a = round(runif(100) * 10), b = round(runif(100) * 10))
df[which(df[,2] == 2),2] <- NA # add NA to second column

apply(df, 2, function(x) sum(x == 1, na.rm = TRUE))

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: My function and NA Values Problem

Temel İspanyolca
Thanks SEZEN and BERGER

Now it is working.

My mistake <- I have written  this statement (na.rm=TRUE) to the wrong
location (after the  sum expression)

Thanks for your kindly responses

Sincerely
Engin YILMAZ

2017-10-27 10:57 GMT+03:00 Ismail SEZEN <[hidden email]>:

>
> > On 27 Oct 2017, at 10:43, Engin YILMAZ <[hidden email]> wrote:
> >
> > Dear R Staff
> >
> > My working file is in the annex. "g1.csv"
> > I have only 2 columns. Rice and coke.
> > I try to execute following(below) function, but do not work.
> > Because "Coke" value has NA values.
> > I try to add "na.rm=True" to the function but do not work
> > How can I solve this problem with this function or another algorithm?
> > (Note: I have normally 450 columns)
> >
> > Sincerely
> > Engin YILMAZ
> >
> >
> > apply(g1, 2, function(c) sum(c==0))
> >
> > Rice Coke
> >   0   NA
>
> A simple reproduciple example always works,
>
> # create sample data
> df <- data.frame(a = round(runif(100) * 10), b = round(runif(100) * 10))
> df[which(df[,2] == 2),2] <- NA # add NA to second column
>
> apply(df, 2, function(x) sum(x == 1, na.rm = TRUE))
>
>
>


--
*Saygılarımla*
Engin YILMAZ

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.