So I am trying to count the number of characters in each word. I have a .db file. with 5 variables and one has 100 sets of words. Here is my code
library(DBI)
library(RSQLite)
library(dplyr)
texts <- dbReadTable(con, "Document")
char <- texts %>% select(words)
str_count(char)
But my output is "argument is not an atomic vector; coercing[1] 563" so the total number of 563 characters but what I want is a list/column were like word 1 has 4 characters, word 2 has 7, word 3 has 2... etc. Any ideas?
select
returns adata.frame
ortbl_df
, whereas you are expecting it to be a vector. Trypull(texts, words)
, or if you must have the pipe, thentexts %>% pull(words)
or just the boring-oldtexts$words
. Or, as Konrad suggested,str_count(texts$words)
or even justnchar(texts$words)
(base R). – r2evans