Skip to Content
R Cookbook
book

R Cookbook

by JD Long, Paul Titer, Jee -Won Lee
May 2022
Beginner to intermediate
667 pages
16h 17m
Korean
Insight
Content preview from R Cookbook
R
172
5장 데이터 구조
󺠣󽴔󻨛󻨓󻇃󺋿
리스트의 원소를 제거하는 방법은 레시피
5
.
10
을, 리스트의 원소들을 조건에 따라
삭제하는 방법은 레시피
5
.
13
을 참고하라.
5.13
󻴿󺅃󻰓󽴔󻕻󻭸󼩃󽴔󺹻󻝳󼞇󻰧󽴔󻮟󻙛󽴔󻳫󺄿󼨧󺋿
󻀇󻳫
조건 검사 결과에 따라 리스트에서 원소를 제거하고 싶다. 예를 들면 정의되지 않았
거나, 음수이거나 기준치보다 작은 원소 등을 제거하려고 한다.
󼩃󺅿󼄔
여러분의 조건이 달성되었을 때
TRUE
를 반환하고, 그렇지 않은 경우
FALSE
를 반환하
는 함수로부터 시작한다. 그러고 나서
purrr
패키지의
discard
함수를 사용해 조건을
만족하는 값들을 제거한다. 예를 들어, 다음의 짧은 코드는
is.na
함수를 사용해서
lst
로부터
NA
값들을 제거한다.
lst <- list(NA, 0, NA, 1, 2)
lst %>%
discard(is.na)
#> [[1]]
#> [1] 0
#>
#> [[2]]
#> [1] 1
#>
#> [[3]]
#> [1] 2
󺙋󻰧
discard
함수는
󻗫󻛯󻉏
(
predicate
), 즉
TRUE
또는
FALSE
를 반환하는 함수를 사용해서
원소를 리스트로부터 제거한다. 서술부는 리스트의 각 원소에 적용되고, 만약 서술
부가
TRUE
를 반환하면 해당 원소는 버려진다. 그 외의 경우에는 유지된다.
lst
라는 리스트에서 문자열을 제거하고 싶다고 해 보자. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

R Cookbook

R Cookbook

Paul Teetor
R Graphics Cookbook

R Graphics Cookbook

Winston Chang
R Cookbook, 2nd Edition

R Cookbook, 2nd Edition

JD Long, Paul Teetor

Publisher Resources

ISBN: 9788966262984