Unknown college 14 days punch notes Day3

Matrix #
m <-matrix (1: 6, nrow = 2, ncol = 3, byrow = T, dimnames = list (c ( 'r1', 'r2'), c ( 'c1', 'c2', 'c3 ')))
# line name, because there are two lines, so if vectors, there are three columns, it is also vectors
m
class (m)
# access data
m [1,1]
m [. 1,]
m [,. 1]
m [C (T, F.),]
m [ 'R1',]
m [. 1,] <- C (100,99,98)
m
m [. 1,] <- 100
m

Transpose #
t (m)

# Array
Array (1:10)
Array (. 1: 10, Dim = C (2,5))

DIM1 <-C ( 'A1', 'A2')
DIM2 <-C ( 'Bl', 'B2', 'B3')
dim3 <-C ( 'C1', 'C2')
Array (. 1: 12 is, Dim C = (2,3,2), the dimnames = List (DIM1, DIM2, dim3))
at array3 <the -array (. 1: 12 is, Dim C = (2,3,2), the dimnames = List (DIM1, DIM2, dim3 ))
at array3 [,, 'C1'] ### actually returns a matrix
array3 [,, c (T, F )]


Data block ##
data.frame ()
Student <-data.frame (C = ID (1002, 1003),
name = C ( 'Lili', 'Bob', "Sam"), can not be less rearmost ## comma
GENDER = c ( 'F', 'M', 'M'), stringsAsFactors = F) ## will be automatically converted into a factor type string
Student
Student [1,1]
Student [. 1,]
Student [,. 1]
Student [, 'ID'] output ## is a vector
student [ 'ID'] ## is the output data block
student $ ID ## output vector
student [c ( 'ID', 'name')]
Student [1,1] <- 1009
Student

 

List ## may contain different types of elements
List1 <-list (A =. 1, B = 'char', C = m, D = Student)
List1
List1 [[. 4]] must be added to the double brackets ## access
List1 [ [ 'D']]
## plus if it Zayang singlet parenthesis
list1 [4] ## will be more than a $,
class (List1 [. 4]) ## is obtained in single quotes list, rather than the original data frame

 

# Work ------------------------------------------------ ----------------------

#1、
matrixA<-matrix(1:12,nrow=3,ncol=4,byrow=F)
matrixB<-matrix(1:12,nrow=3,ncol=4,byrow=T)

##2、
matrixB[,1]<-100


. 3 #,
WTDATA <-data.frame (ID = C (l, 2,3), name = C ( 'John Doe', 'John Doe', 'Wang Wu'), weight = c (60,70,80 ), stringsAsFactors = F)

 

#4、
wtdata[c(T,F,T),,]

#5、
wtlist<-list(a=matrixA,b=matrixB,c=wtdata)

# 6,
wtlist [1]

Guess you like

Origin www.cnblogs.com/chayibaishanlqy/p/11574846.html