Professional Documents
Culture Documents
#Practical:6 #Constructing Data Objects: # (A) Making Lists
#Practical:6 #Constructing Data Objects: # (A) Making Lists
#Practical:6 #Constructing Data Objects: # (A) Making Lists
sample1=c(5,6,9,12,8)
sample1
sample2=c(7,9,13,10,NA)
sample1;sample2
my.frame=data.frame(sample1,sample2)
my.frame
response=c(5,6,9,12,8,7,9,13,10)
predictor=c(rep('open',5),rep('closed',4)) #rep(item,times)
response;predictor
my.frame2=data.frame(response,predictor)
my.frame2
mow;unmow
length(unmow)=5
mow;unmow
length(unmow)=4
mow;unmow
length(unmow)=length(mow) #length(short.vector)=length(long.vector)
mow;unmow
#(D)Matrix Objects:
#cbind() to use the samples as columns
sample1;sample2
cmat=cbind(sample1,sample2)
cmat
rmat=rbind(sample1,sample2)
rmat
sample3
mix.mat=cbind(sample1,sample2,sample3)
mix.mat
#all the data items are convertd to characters; check using str()
str(mix.mat)
#if you want to extract numbers from a "mixed" matrix
#you must force the items to be numeric like so:
as.numeric(mix.mat[,1])
mix.mat[,1]=as.numeric(mix.mat[,1])
mix.mat
sample1;sample2
all.samples=c(sample1,sample2)
all.samples
mat=matrix(all.samples,nrow = 2)
mat
mat=matrix(all.samples,ncol = 2)
mat
cnam=c('Sample1','Sample2')
rnam=c('Site1','Site2','Site3','Site4','Site5')
mat=matrix(all.samples,ncol = 2,dimnames = list(rnam,cnam))
mat