Dataframe and matrices
an anonymous user
·
R
·

#creating a dataframe employee<-data.frame(empid=c(12,15,11,13,18),empname=c("raj","ravi","prem","kishore","ajay"),salary=c(20,30,40,50,60),start_date=as.Date(c("2020-12-26","2020-12-2","2020-11-26","2020-10-3","2020-12-21")),stringsAsFactors=FALSE) employee #extracting data from dataframe employee[,1:2] employee[c(2,5),] employee[,c(1,3)] employee[c(3,5),c(2,4)] employee[2,4] #summary of dataframe summary(employee) #extracting data from dataframe using columnnames employee$salary #matrix m<-matrix(1:9,3,3,byrow = TRUE ) m #assigning row name LETTERS MENTIONING ALPHABETICAL rownames(m)<-LETTERS[1:3] #assigning column name colnames(m)<-LETTERS[24:26] #transposition of matrix t() P<-t(m) P #rbind and cbind rbind(a=1:3,b=c(4,8,6),c=c(9,2,8)) cbind(a=1:3,b=c(4,8,6),c=c(9,2,8))
Click on the Run button to get started.
The code/input has changed since you last clicked on Run. Click it
again to see the updated changes.
Comments