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

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("Petal.Length", "Petal.Width"))]
head(df2)
df <- iris
df2 <- df[,!(names(df) %in% c("Petal.Length", "Petal.Width"))]
head(df2)

4 같이 보기[ | ]

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