I have looked around for what I thought would be a simple solution, but nothing has proven helpful so far. Here is what I'd like to do:
1) Separately count the total number of 3 different strings in a specific data frame column, 2) put those 3 counts into a new vector, 3) add that vector to another data frame. Here is what I've tried:
> x <- c("Type1", "Type1", "Type2", "Type2")
> Column_Counts <- table(x)
> Type_One <- Column_Counts[names(Column_Counts)=="Type1"]
> Type_One <- as.numeric(Type_One)
> Type_Two <- Column_Counts[names(Column_Counts)=="Type2"]
> Type_Two <- as.numeric(Type_Two)
> Type_Three <- Column_Counts[names(PS_Count)=="Type3"]
> Type_Three <- as.numeric(Type_Three)
> New_Vector <- c(Type_One, Type_Two, Type_Three)
Here's the problem: sometimes "Type3" doesn't show up in my report, and if so I need it to be counted as zero, but Type_Three has value "numeric (empty)" and doesn't get added to the new vector.
> New_vector
[1] 2 2
#I need New_vector to be [1] 2, 2, 0
I need Type_Three to = 0, not "numeric (empty)". Here is what I tried:
> if (Type_Three == "(empty)")
{Type_Three <- 0}
#Error in if (CR_Des == "(empty)") { : argument is of length zero
Also:
> if (length(Type_Three == 0)
{Type_Three <- 0}
#This does nothing, even though the length is 0.
Any help is greatly appreciated.