"R 데이터프레임 컬럼명으로 컬럼 제거"의 두 판 사이의 차이

25번째 줄: 25번째 줄:
==방법 2: names()==
==방법 2: names()==
<syntaxhighlight lang='r' run>
<syntaxhighlight lang='r' run>
df = iris
df <- iris
head(df)
head(df)
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='r' run>
<syntaxhighlight lang='r' run>
df = iris
df <- iris
df2 = df[!(names(df) %in% c("English","Math"))]
df2 <- df[!(names(df) %in% c("English","Math"))]
head(df2)
head(df2)
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='r' run>
<syntaxhighlight lang='r' run>
df = iris
df <- iris
df2 = df[,!(names(df) %in% c("English","Math"))]
df2 <- df[,!(names(df) %in% c("English","Math"))]
head(df2)
head(df2)
</syntaxhighlight>
</syntaxhighlight>

2021년 10월 27일 (수) 00:23 판

1 개요

R 데이터프레임 컬럼명으로 컬럼 제거

2 방법 1: subset()

df <- iris
head(df)
df <- iris
df2 <- subset(df, select=-Petal.Length)
head(df2)
df <- iris
df2 <- subset(df, select=-c(Petal.Length))
head(df2)
df <- iris
df2 <- subset(df, select=-c(Petal.Length, Petal.Width))
head(df2)

3 방법 2: names()

df <- iris
head(df)
df <- iris
df2 <- df[!(names(df) %in% c("English","Math"))]
head(df2)
df <- iris
df2 <- df[,!(names(df) %in% c("English","Math"))]
head(df2)

4 같이 보기

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