R:通过循环迭代字符串元素

R: Iterating a string element via loop

提问人:Aaron Dent 提问时间:1/12/2023 更新时间:1/12/2023 访问量:28

问:

我正在尝试在一段时间内嵌入一个 for 循环,该循环采用以下日期“last_contribution_receipt_date=2016-01-01”,并在每次满足给定条件时将最后一个 01 值增加一个整数。一旦last_indexes值为 null,循环应移动到下一个日期。

while (more_pages) {
  
  # Create the full API URL by combining the base URL, the "last_indexes" object, and the extra parameters
  API_URL= paste0(base,extra, last_indexes)
  
  # Retrieve and parse the data for each page
  raw_data <- GET(API_URL)
  stuff <- fromJSON(rawToChar(raw_data$content), flatten = TRUE)
  
  
  
  # Bind the results from each iteration to the empty data frame
  
  
  dfs = rbind(dfs, stuff$results)
  
  
  # Update the "last_index" value in the "last_indexes" object with the latest value
  last_indexes = stuff[["pagination"]][["last_indexes"]][["last_index"]]
  print(stuff[["pagination"]][["last_indexes"]][["last_index"]])
}
print(API_URL)

我尝试了一个 for 循环,但无法弄清楚如何在末尾隔离字符串的一部分,而不是在数组中循环整数。

r string 替换 while-loop

评论

0赞 Community 1/12/2023
请提供足够的代码,以便其他人可以更好地理解或重现问题。

答: 暂无答案