(R) data.frame function / Way to make data frame 데이터 프레임 만들기 R
Way to make a data frame
data fame is mostly used data structure which consists of columns(Variables) and rows(Cases)
1st way to make a data frame
> student<-c("Jane","Dora","Beth","Park")
> class<-c(1,3,2,2)
> height<-c(153,172,165,180)
> height_of_students<-data.frame(student,class,height)
> height_of_students
student class height
1 Jane 1 153
2 Dora 3 172
3 Beth 2 165
4 Park 2 180
'height_of_students' become the data frame which consists of 3 variables ('students,' 'class,' 'height') and 4 cases.
2nd way to make a data frame ( ※ stringsAsFactor=F)
> final_score<-data.frame(student=c("Jane","Dora","Beth","Park"),math=c(70,90,50,100), science=c(90,30,80,100),stringsAsFactors = F)
> final_score
student math science
1 Jane 70 90
2 Dora 90 30
3 Beth 50 80
4 Park 100 100
'final_score' becomes the data frame which consists of 3 variables('student,' 'math,' 'science,') and 4 cases('Jane,' 'Dora,' 'Beth,' 'Park')