標(biāo)題
指出當(dāng)前目錄
此為工作目錄截圖
建立六個(gè)向量
數(shù)值络凿、字符串骡送、邏輯值
getwd()
getwd用于顯示當(dāng)前目錄
數(shù)據(jù)結(jié)構(gòu)練習(xí)
之前已經(jīng)寫過了向量這兒就不寫了,下面做一個(gè)矩陣絮记,數(shù)組
矩陣建立了一個(gè)7*7的摔踱,數(shù)組顯示了一下
如果矩陣?yán)镆畛鋽?shù)據(jù)的話,就要在前面補(bǔ)上一下數(shù)據(jù)怨愤,下面是例子
把1到49按列填充矩陣
數(shù)據(jù)框:先把每一列寫好派敷,然后組成一個(gè)數(shù)據(jù)框
一個(gè)5*6數(shù)據(jù)框
把上面所有的東西都整合到一起整成一個(gè)列表
右邊顯示all是一個(gè)有三個(gè)元素的列表
因?yàn)橄乱淮沃挥昧藄tudents,所以清除別的不用的變量,只留下students
把不是student的變量全部清除
最后貼一下代碼
c(1,2,3,4) #元素為s數(shù)值
c('dick','dk','dkk','cbw') #元素為字符串
c(TRUE,FALSE,TRUE) #元素為邏輯值
#矩陣
a = matrix(1:49,nrow=7,ncol=7)
#數(shù)組 array
dim1 = c(paste0('a',1:2))
dim2 = c(paste0('b',1:3))
dim3 = c(paste0('c',1:4))
b = array(1:24,c(2,3,4),dimnames = list(dim1,dim2,dim3))
#array(vector,dimmensions,dimnames)
#寫一個(gè)數(shù)據(jù)框:定義每一列向量然后組合
#注意篮愉,每一列數(shù)據(jù)量要一樣多般眉,不然會(huì)報(bào)錯(cuò)
stuname<- c('cbw','dick','jd','xyr','hyk')
age <- c(seq(from=1,to=5))
hobby <- c('ball','box','game','box','game')
clothes <- c('jk','T-shirt','T-shirt','jacket','coat')
single <- c(T,T,F,NA,F)
NO <- c(paste0('no.',1:5,' man'))
student <- data.frame(stuname,age,hobby,clothes,single,NO)
#把上面的東西組合成一個(gè)列表
all <- list(a,b,student)
#最后清除掉所有不需要的變量,只留下需要后面import的變量
a <- ls()
rm(list = a[which(a!='student')])