immaprogrammingnoob
immaprogrammingnoob

Reputation: 167

Getting the count of a value in a column

I'm trying to clean up a large data set. I have code that will return what the unique values are of a column in a data table in R. But when I go to get the count for how many times a specific value occurs, I get an "NA." Any help is much appreciated.

> RtpStateBitfieldunique<-sort(unique(train$RtpStateBitfield))
> RtpStateBitfieldunique
[1]  0  1  3  5  7  8 35
> sum(is.na(train$RtpStateBitfield))
[1] 32318
> sum(train$RtpStateBitfield==35)
[1] NA
> sum(train$RtpStateBitfield=="35")
[1] NA

Upvotes: 1

Views: 98

Answers (1)

NM_
NM_

Reputation: 1999

To get the counts of data, you can use the table function:

> table(train$RtpStateBitfield)

However this will not give you the number of values that are NA. In order to get a count of the NA's, you can use

> sum(is.na(train$RtpStateBitfield))

Upvotes: 3

Related Questions