목록의 목록이 여러 개 있으며 각 목록에서 추출해야하는 변수는 약간 다른 방식으로 중첩되어 있습니다. 변수를 검색하고 추출하는 간단한 방법이 있습니까?R : 목록 목록에서 변수 검색 및 추출
예
list1 <- list(AccountingSupplierParty = list(Party = list(PartyName = "Company Incorporated", PartyType = "The worst party")), DataSet = "Data Set 1")
list2 <- list(SupplierParty = list(Party = list(PartyName = "Company A/S", PartyType = "The best party")), DataSet = "Data Set 2")
내가 "PartyName"을 추출하고 싶습니다 나열합니다. 내가 좋아하는 것
Company1 <- list1$AccountingSupplierParty$Party$PartyName
Company2 <- list2$SupplierParty$Party$PartyName
출력은 다음과 같습니다 :
"Company Incorporated"
"Company A/S"
당신은 당신의 예를 확인해야합니다 [재현] (http://stackoverflow.com/questions/5963269/how-to-make-a-great -r-reproducible-example # 5963610)에'dput (list1)'과'dput (list2)'의 결과를 더한다. – alistaire
감사합니다, 지금 예제를 만들 것입니다 –
변경된 부분을 추상화 할 수 있습니다 :'sapply (list (list1, list2), function (x) {x [[1]] $ Party $ PartyName})' – alistaire