Home > Net >  How to break Char Vectors up at defined terms?
How to break Char Vectors up at defined terms?

Time:10-02

I am scraping data off a website using rvest() for the first time.

It gave me a character vector that I am trying to split and convert to a data frame with columns.

How do you turn this vector:

char.vector <- c("John DoeTeacherSpeaksEnglishJapaneseRateUSD 10Video Intro","JaneTutorSpeaksJapaneseFrenchRateUSD 15Video Intro")

...into this data frame with columns:

Name Role English Japanese French Rate_USD
John Doe Teacher 1 1 0 10
Jane Tutor 0 1 1 15

Splitting on spaces or character position is problematic. Is there maybe a way to create a vector of all the words I want to split at and use it as the split argument?

split.vector <- c("Teacher", "Tutor", "Speaks", "English", "Japanese", "French", "Rate", "Video")

My code and url:

EN.char <- read_html("https://www.italki.com/teachers/english") %>%
             html_nodes(".teacher-card") %>%
             html_text()

EN.char

CodePudding user response:

So, as there are potentially different numbers of languages for each entry, I shamelessly took the approach used by enter image description here

  • Related