I got a dataset named full and one of its Column is Breed as shown below.
Breed
Shetland Sheepdog Mix
Domestic Shorthair Mix
Pit Bull Mix
Domestic Shorthair Mix
Lhasa Apso/Miniature Poodle
Cairn Terrier/Chihuahua Shorthair
Domestic Shorthair Mix
Domestic Shorthair Mix
American Pit Bull Terrier Mix
Cairn Terrier
Domestic Shorthair Mix
Miniature Schnauzer Mix
Pit Bull Mix
Yorkshire Terrier Mix
Great Pyrenees Mix
Domestic Shorthair Mix
Domestic Shorthair Mix
Pit Bull Mix
Angora Mix
Flat Coat Retriever Mix
Queensland Heeler Mix
Domestic Shorthair Mix
Plott Hound/Boxer
What I required is,
I need to get the frequency for each unique value in the column.
I have extracted the BreedType and the frequency as shown below. (The breed column is given the name as BreedType ) Then if the frequency of each BreedType is less than 66, using an if condition I need to have a new column with 'F' and if greater than 66 need to assign the column with the value of 'Breedtype'.
Assign FALSE for Breed values where Breed frequency is less than 66.
df$Breed <- data.frame(full$Breed)
setDT(df)
dt1 <- copy(df)
dt1[, c("Frequency", "TrueFalse") := .(.N, ifelse(.N < 66, "FALSE", Breed)), by = Breed]
dt1<-data.frame(dt1)
But my result set gets the answer set like this with the shown error.
Error in [.data.table
(dt1, , :=
(c("Frequency", "TrueFalse"), .(.N, :
Type of RHS ('integer') must match LHS ('character'). To check and coerce would impact performance too much for the fastest cases. Either change the type of the target column, or coerce the RHS of := yourself (e.g. by using 1L instead of 1)
I tried several times but I was not able to get the result looked. Can someone please help
Also when the full$Breed is used again the result set is looking like this. and not what expected but the frequency is giving correctly,
df$Breed <- data.frame(full$Breed)
setDT(df)
dt1 <- copy(df)
dt1[, c("Frequency", "TrueFalse") := .(.N, ifelse(.N < 66, "FALSE", full$Breed)), by = full$Breed]
dt1<-data.frame(dt1)
Full<-cbind2(dt1, full)
Can someone please help to figureout what the issue is!