dplyr mutate throws "Error: invalid subscript type 'closure'" error

3.1k Views Asked by At

I'm trying to use the sentiment_by in sentimentR with dplyr's mutate

This for example works: content <- mutate(content, word_count = sentiment_by(story)$word_count)

but

This for example works: content.sd <- mutate(content, word_count = sentiment_by(story)$sd)

gives the error Error: invalid subscript type 'closure'

but sentiment_by(content$story[1]) works

Any help would be greatly appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

You can use the following instead

content <- mutate(content, stdev = sentiment_by(story)[["sd"]])