"R ifelse()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight , -</source> +</syntaxhighlight>))
 
3번째 줄: 3번째 줄:
* "Conditional Element Selection"
* "Conditional Element Selection"


<source lang='r' run>
<syntaxhighlight lang='r' run>
a <- c(3, 1, 4, 1, 5, 9)
a <- c(3, 1, 4, 1, 5, 9)
ifelse(a %% 2 == 0, "even", "odd")
ifelse(a %% 2 == 0, "even", "odd")
</source>
</syntaxhighlight>
<source lang='r' notebook>
<syntaxhighlight lang='r' notebook>
df <- read.table( header=TRUE, sep=",", stringsAsFactors=FALSE, text="
df <- read.table( header=TRUE, sep=",", stringsAsFactors=FALSE, text="
id,score
id,score
17번째 줄: 17번째 줄:
")
")
df
df
</source>
</syntaxhighlight>
<source lang='r' notebook>
<syntaxhighlight lang='r' notebook>
df$result <- ifelse(df$score >= 50, "pass", "fail")
df$result <- ifelse(df$score >= 50, "pass", "fail")
df
df
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2021년 4월 14일 (수) 02:00 기준 최신판

1 개요[ | ]

R ifelse()
  • "Conditional Element Selection"
a <- c(3, 1, 4, 1, 5, 9)
ifelse(a %% 2 == 0, "even", "odd")
df <- read.table( header=TRUE, sep=",", stringsAsFactors=FALSE, text="
id,score
1,40
2,60
3,45
4,50
5,25
")
df
df$result <- ifelse(df$score >= 50, "pass", "fail")
df

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}