0

I am trying to run this line of code from a Kaggle script:

df1 <- combined %>%
count(name = character, drilldown = character) %>% 
arrange(desc(n)) %>% 
head(9) %>% 
rename(y = n)

However, when I run this code, I receive this error message:

Error: `name` must be a single string.

"Combined" is a dataframe containing 2 variables (character and dialogue, both of which are "character" variables.

ep4 <- data.frame(character  = c("Luke", "Leia"),
                  dialogue = c("Hello", "world")
                  )
                  
ep5 <- data.frame (character  = c("Darth vader", "Sidious"),
                   dialogue = c("My", "name")
                   )

ep6 <- data.frame (character  = c("R2D2", "ObiWan"),
                   dialogue = c("is", "Essan")
                   )
combined <- bind_rows(ep4, ep5, ep6)

str(combined):
'data.frame':   6 obs. of  2 variables:
 $ character: chr  "Luke" "Leia" "Darth vader" "Sidious" ...
 $ dialogue : chr  "Hello" "world" "My" "name" ...

I am not sure what I am doing wrong here. I am using the count() function from the dpylr package, not plyr. There is an issue with the "name" argument from the count function. If I remove the "name" argument, the code runs, but the Pie Chart that is created later on (using df1 as its data) does not contain the names of the characters per slice.

Here is the Kaggle script: https://www.kaggle.com/couyang/star-wars-interac-drilldown-sentiment-analysis/execution

Behnam Hedayat
  • 837
  • 4
  • 18
Essan Rago
  • 77
  • 1
  • 5
  • Hey, can you what the combined data looks like? – elielink May 27 '21 at 13:56
  • Welcome to SO, EssanRago! Please don't make us guess what `combined` looks like, either use a public database, or please provide unambiguous, easily-used data, preferably made programmatically with `data.frame(.)` or paste the output from `dput(x)` (where `x` is a small representative sample of the data, enough to show the variability of it). Please see https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. Thanks! – r2evans May 27 '21 at 14:03

1 Answers1

0

The following is probably what you want

df1 <- combined %>%
count(drilldown = character) %>% 
arrange(desc(n)) %>% 
head(9) %>% 
rename(y = n)

The error you are getting is that it is expecting a character to be assigned to the name argument. If you were to do this, you would need to adjust your pipeline as follows:

df1 <- combined %>%
count(drilldown = character, name = "counts") %>% 
arrange(desc(counts)) %>% 
head(9) %>% 
rename(y = counts)
Justin Landis
  • 1,981
  • 7
  • 9