R 从包含嵌套列表的表列中提取第一个值

R 从包含嵌套列表的表列中提取第一个值,r,R,在RStudio中,我正在执行openweathermap的api。 返回的json被转换为数据帧 我用来获取JSON的代码是: text2 <- GET('https://api.openweathermap.org/data/2.5/onecall/timemachine?lat=43.15&lon=-89.29&dt=1621425600&appid=yourappidhere') jsonOpenWeather <- fromJSON(rawToCha

在RStudio中,我正在执行openweathermap的api。 返回的json被转换为数据帧

我用来获取JSON的代码是:

text2 <- GET('https://api.openweathermap.org/data/2.5/onecall/timemachine?lat=43.15&lon=-89.29&dt=1621425600&appid=yourappidhere')
jsonOpenWeather <- fromJSON(rawToChar(text2$content))

text2我们可以使用
sapply
循环对象的“天气”列,提取
main
列并获得第一个观测值

jsonOpenWeather2 <- sapply(jsonOpenWeather$weather, function(x) x$main[1])

jsonOpenWeather2感谢您的回复。我尝试了您的代码,但很遗憾,我返回了0的列表。我确实找到了一个解决方案,尽管它并不优雅。我做了以下操作:
b=“rain”
(I in 1:length(test$dt))
{
`a=tester[[I]][2][[1]][1]``b=rbind(b,a)`
main@S.hyl而您的
GET
代码是不可复制的,所以这仅仅是基于descrption@S.Hyland您的代码显示
test
tester
是否相同