nrow()

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

nrow()

Sandra Stankowski
Hey there,

I tried to count the number of rows, where my data isn't NaN in a
certain column.

this was my guess:

(given is a data frame with 2069 rows and 17 cols)

NROW(data[jan,16] != NaN)

("jan" is defined this way: jan <- which(data[,2]==1, arr.ind= TRUE))


but I only get the number of columns where my data is "1" in the second
col. R isn't removing the NaN.
na.rm isn't working here.

I would appreciate your help.

______________________________________________
[hidden email] mailing list
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: nrow()

Peter Ehlers
?is.nan

Peter Ehlers

On 2011-02-22 07:11, Sandra Stankowski wrote:

> Hey there,
>
> I tried to count the number of rows, where my data isn't NaN in a
> certain column.
>
> this was my guess:
>
> (given is a data frame with 2069 rows and 17 cols)
>
> NROW(data[jan,16] != NaN)
>
> ("jan" is defined this way: jan<- which(data[,2]==1, arr.ind= TRUE))
>
>
> but I only get the number of columns where my data is "1" in the second
> col. R isn't removing the NaN.
> na.rm isn't working here.
>
> I would appreciate your help.
>
> ______________________________________________
> [hidden email] mailing list
> 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.

______________________________________________
[hidden email] mailing list
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: nrow()

Erik Iverson-3
In reply to this post by Sandra Stankowski
Sandra,

Please provide a small, reproducible example of this issue.
You probably want to use ?is.nan and not the inequality
operator.

Similar example, contrast:

x <- NA
is.na(x)
x == NA

Sandra Stankowski wrote:

> Hey there,
>
> I tried to count the number of rows, where my data isn't NaN in a
> certain column.
>
> this was my guess:
>
> (given is a data frame with 2069 rows and 17 cols)
>
> NROW(data[jan,16] != NaN)
>
> ("jan" is defined this way: jan <- which(data[,2]==1, arr.ind= TRUE))
>
>
> but I only get the number of columns where my data is "1" in the second
> col. R isn't removing the NaN.
> na.rm isn't working here.
>
> I would appreciate your help.
>
> ______________________________________________
> [hidden email] mailing list
> 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.

______________________________________________
[hidden email] mailing list
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: nrow()

Mohamed Lajnef
In reply to this post by Sandra Stankowski
Hi Sandra,

What about ?is.na function ?

Hope this help

Regards,
ML



Le 22/02/11 16:11, Sandra Stankowski a écrit :
> NROW(data[jan,16] != NaN)


--
####################################
Mohamed Lajnef,IE INSERM U955 eq 15#
Pôle de Psychiatrie   #
Hôpital CHENEVIER                  #
40, rue Mesly                      #
94010 CRETEIL Cedex FRANCE         #
[hidden email]           #
tel : 01 49 81 31 31 (poste 18467) #
Sec : 01 49 81 32 90               #
fax : 01 49 81 30 99               #
####################################



        [[alternative HTML version deleted]]


______________________________________________
[hidden email] mailing list
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: nrow()

Sandra Stankowski
In reply to this post by Erik Iverson-3
is.na function does'nt seem to work, but maybe I'm just dealing with it
in a wrong way.

here's an example

 > m <- c(2, 3, 5, 6, 3, 7, -99, -99, 6)
 > n <- c(1,1,1,1,1,2,2,2,2)

so my matrix contains certain missing values

 > m[m==-99] <- NA
 > o <- data.frame(m, n)
 > o
    m n
1  2 1
2  3 1
3  5 1
4  6 1
5  3 1
6  7 2
7 NA 2
8 NA 2
9  6 2

"2" stands for february

 > february <- which(o[,2]==2, arr.ind = TRUE)
 > prec_feb <- sum(o[february,1], na.rm = TRUE)
 > prec_feb
[1] 13

And now I need to know the exact number of rows, where "m"  contains a
value. to know how many days a month give any information. (to create
monthly means and stuff)

hope this explains, what I need to know.

Thanks,
S.





Am 22.02.2011 16:50, schrieb Erik Iverson:

> Sandra,
>
> Please provide a small, reproducible example of this issue.
> You probably want to use ?is.nan and not the inequality
> operator.
>
> Similar example, contrast:
>
> x <- NA
> is.na(x)
> x == NA
>
> Sandra Stankowski wrote:
>> Hey there,
>>
>> I tried to count the number of rows, where my data isn't NaN in a
>> certain column.
>>
>> this was my guess:
>>
>> (given is a data frame with 2069 rows and 17 cols)
>>
>> NROW(data[jan,16] != NaN)
>>
>> ("jan" is defined this way: jan <- which(data[,2]==1, arr.ind= TRUE))
>>
>>
>> but I only get the number of columns where my data is "1" in the
>> second col. R isn't removing the NaN.
>> na.rm isn't working here.
>>
>> I would appreciate your help.
>>
>> ______________________________________________
>> [hidden email] mailing list
>> 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.
>

______________________________________________
[hidden email] mailing list
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: nrow()

Erik Iverson-3


Sandra Stankowski wrote:
> is.na function does'nt seem to work, but maybe I'm just dealing with it
> in a wrong way.
>
> here's an example
>
>  > m <- c(2, 3, 5, 6, 3, 7, -99, -99, 6)
>  > n <- c(1,1,1,1,1,2,2,2,2)
>
> so my matrix contains certain missing values

Thank you for the example.
You're constructing a data.frame, not a matrix.
Those are two separate classes in R.

>  > m[m==-99] <- NA
>  > o <- data.frame(m, n)
>  > o
>    m n
> 1  2 1
> 2  3 1
> 3  5 1
> 4  6 1
> 5  3 1
> 6  7 2
> 7 NA 2
> 8 NA 2
> 9  6 2
>
> "2" stands for february
>
>  > february <- which(o[,2]==2, arr.ind = TRUE)
>  > prec_feb <- sum(o[february,1], na.rm = TRUE)
>  > prec_feb
> [1] 13
>
> And now I need to know the exact number of rows, where "m"  contains a
> value. to know how many days a month give any information. (to create
> monthly means and stuff)

You might find ?complete.cases useful.

Also try:

sum(!is.na(o$m))

?tapply may also be useful in general: e.g.,

tapply(o$m, o$n, mean, na.rm  = TRUE)

None of this is tested...

>
> hope this explains, what I need to know.
>
> Thanks,
> S.
>
>
>
>
>
> Am 22.02.2011 16:50, schrieb Erik Iverson:
>> Sandra,
>>
>> Please provide a small, reproducible example of this issue.
>> You probably want to use ?is.nan and not the inequality
>> operator.
>>
>> Similar example, contrast:
>>
>> x <- NA
>> is.na(x)
>> x == NA
>>
>> Sandra Stankowski wrote:
>>> Hey there,
>>>
>>> I tried to count the number of rows, where my data isn't NaN in a
>>> certain column.
>>>
>>> this was my guess:
>>>
>>> (given is a data frame with 2069 rows and 17 cols)
>>>
>>> NROW(data[jan,16] != NaN)
>>>
>>> ("jan" is defined this way: jan <- which(data[,2]==1, arr.ind= TRUE))
>>>
>>>
>>> but I only get the number of columns where my data is "1" in the
>>> second col. R isn't removing the NaN.
>>> na.rm isn't working here.
>>>
>>> I would appreciate your help.
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> 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.
>>
>

______________________________________________
[hidden email] mailing list
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: nrow()

Sandra Stankowski
Thanks.
I made it!

Best wishes,
S.



Am 22.02.2011 17:41, schrieb Erik Iverson:

>
>
> Sandra Stankowski wrote:
>> is.na function does'nt seem to work, but maybe I'm just dealing with
>> it in a wrong way.
>>
>> here's an example
>>
>> > m <- c(2, 3, 5, 6, 3, 7, -99, -99, 6)
>> > n <- c(1,1,1,1,1,2,2,2,2)
>>
>> so my matrix contains certain missing values
>
> Thank you for the example.
> You're constructing a data.frame, not a matrix.
> Those are two separate classes in R.
>
>> > m[m==-99] <- NA
>> > o <- data.frame(m, n)
>> > o
>>    m n
>> 1  2 1
>> 2  3 1
>> 3  5 1
>> 4  6 1
>> 5  3 1
>> 6  7 2
>> 7 NA 2
>> 8 NA 2
>> 9  6 2
>>
>> "2" stands for february
>>
>> > february <- which(o[,2]==2, arr.ind = TRUE)
>> > prec_feb <- sum(o[february,1], na.rm = TRUE)
>> > prec_feb
>> [1] 13
>>
>> And now I need to know the exact number of rows, where "m"  contains
>> a value. to know how many days a month give any information. (to
>> create monthly means and stuff)
>
> You might find ?complete.cases useful.
>
> Also try:
>
> sum(!is.na(o$m))
>
> ?tapply may also be useful in general: e.g.,
>
> tapply(o$m, o$n, mean, na.rm  = TRUE)
>
> None of this is tested...
>
>>
>> hope this explains, what I need to know.
>>
>> Thanks,
>> S.
>>
>>
>>
>>
>>
>> Am 22.02.2011 16:50, schrieb Erik Iverson:
>>> Sandra,
>>>
>>> Please provide a small, reproducible example of this issue.
>>> You probably want to use ?is.nan and not the inequality
>>> operator.
>>>
>>> Similar example, contrast:
>>>
>>> x <- NA
>>> is.na(x)
>>> x == NA
>>>
>>> Sandra Stankowski wrote:
>>>> Hey there,
>>>>
>>>> I tried to count the number of rows, where my data isn't NaN in a
>>>> certain column.
>>>>
>>>> this was my guess:
>>>>
>>>> (given is a data frame with 2069 rows and 17 cols)
>>>>
>>>> NROW(data[jan,16] != NaN)
>>>>
>>>> ("jan" is defined this way: jan <- which(data[,2]==1, arr.ind= TRUE))
>>>>
>>>>
>>>> but I only get the number of columns where my data is "1" in the
>>>> second col. R isn't removing the NaN.
>>>> na.rm isn't working here.
>>>>
>>>> I would appreciate your help.
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> 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.
>>>
>>
>

______________________________________________
[hidden email] mailing list
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.