1 개요[ | ]
- R 데이터프레임 컬럼명으로 컬럼 선택
2 방법 1: subset()[ | ]
R
CPU
0.3s
MEM
53M
0.3s
Copy
df = iris
head(df)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa
R
Copy
df = iris
df2 = subset(df, select=Petal.Length)
head(df2)
Loading
R
Copy
df = iris
df2 = subset(df, select=c(Petal.Length))
head(df2)
Loading
R
Copy
df = iris
df2 = subset(df, select=c(Petal.Length, Petal.Width))
head(df2)
Loading
3 방법 2: names()[ | ]
R
Copy
df = iris
head(df)
Loading
R
Copy
df = iris
df2 = df[(names(df) %in% c("Petal.Length","Petal.Width"))]
head(df2)
Loading
4 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.