반응형
1. 각각의 벡터를 만들고 합치는 방법
english <- c(90,80,60,70)
english
math <- c(50,60,100,20)
math
df_midterm <- data.frame(english, math)
df_midterm
klas <- c(1,1,2,2)
klas
df_midterm <- data.frame(english,math,klas)
df_midterm
> english <- c(90,80,60,70)
> english
[1] 90 80 60 70
> math <- c(50,60,100,20)
> math
[1] 50 60 100 20
>
> df_midterm <- data.frame(english, math)
> df_midterm
english math
1 90 50
2 80 60
3 60 100
4 70 20
>
> class <- c(1,1,2,2)
> class
[1] 1 1 2 2
2. 바로 만드는 방법
df2_midterm <- data.frame(english2=c(90,80,60,70),
math2=c(50,60,100,20),
class2=c(1,1,2,2))
df2_midterm
> df2_midterm <- data.frame(english2=c(90,80,60,70),
+ math2=c(50,60,100,20),
+ class2=c(1,1,2,2))
> df2_midterm
english2 math2 class2
1 90 50 1
2 80 60 1
3 60 100 2
4 70 20 2
3. 데이터프레임의 속성 읽기
dataframe$col
df=data.frame(var1=c(5,3,4),
var2=c(2,6,1))
df$var1
> df=data.frame(var1=c(5,3,4),
+ var2=c(2,6,1))
> df$var1
[1] 5 3 4
4. 파생속성 만들기(속성추가하기)
df=data.frame(var1=c(5,3,4),
var2=c(2,6,1))
df$var_sum=df$var1+df$var2
df$var_mean=(df$var1+df$var2)/2
df
> df=data.frame(var1=c(5,3,4),
+ var2=c(2,6,1))
> df$var_sum=df$var1+df$var2
> df$var_mean=(df$var1+df$var2)/2
> df
var1 var2 var_sum var_mean
1 5 2 7 3.5
2 3 6 9 4.5
3 4 1 5 2.5
반응형