0
data <-rjson:: fromJSON (file='CA_category_id.json')

category_id <- list()
d <-rjson:: fromJSON(file='CA_category_id.json')
for (category in d$items) {
  category_id[[category$id]] <- category$snippet$title
}

vedio5$category <- category_id[vedio5$category_id]
vedio5$category <- category_id[vedio5$category_id]
for (category in vedio5) {
  vedio5$category <- category_id[vedio5$category_id]
}

I can not understand this code knowing that : Each of the JSON file contains id ranging from 1 to 44 (both inclusive). And with each id is given its category and other information related to title, kind etc. required is: use any one of the JSON files to map category to category id in our data frame.

how to map category to category id in our data frame?

  • 6
    Are you tied to ‘rjson’? ‘jsonlite’ by default unwraps JSON into a data.frame, if possible. – Konrad Rudolph Aug 08 '23 at 11:58
  • 2
    Welcome to SO, saga Mohamed! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Aug 08 '23 at 13:20

0 Answers0