dataframe - Reading in Data.Frames with Strings as factors = False in R using chain operator -


i have table source reads data frame. know default, external sources read data frames factors. i'd apply stringsasfactors=false in data frame call below, throws error when this. can still use chaining , turn stringsasfactors=false?

library(rvest) pvbdata <- read_html(pvburl) pvbdf <- pvbdata %>% html_nodes(xpath = `//*[@id="ajax_result_table"]`) %>%  html_table() %>%  data.frame()  data.frame(,stringsasfactors=false)  <- throws error 

i know simple, i'm having trouble finding way make work. thank help.

though statement should logically data.frame(stringsasfactors=false) if applying chaining, statement doesn't produce required output.

the reason misunderstanding of use of stringsasfactors option. option works if make data.frame column column. example:

a <- data.frame(x = c('a','b'),y=c(1,2),stringsasfactors = t) str(a)  'data.frame':   2 obs. of  2 variables:  $ x: factor w/ 2 levels "a","b": 1 2  $ y: num  1 2  <- data.frame(x = c('a','b'),y=c(1,2),stringsasfactors = f) str(a)  'data.frame':   2 obs. of  2 variables:  $ x: chr  "a" "b"  $ y: num  1 2 

if give data.frame input, stringsasfactors option doesn't work

solution:

store chaining result variable this:

library(rvest) pvbdata <- read_html(pvburl) pvbdf <- pvbdata %>% html_nodes(xpath = `//*[@id="ajax_result_table"]`) %>%  html_table() 

and apply command:

data.frame(as.list(pvbdf),stringsasfactors=f) 

update:

if column factor, can't convert character vector using command. better first as.character , retry.

you may refer change stringsasfactors settings data.frame more details.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -