- Create a matrix for the sequence 1 through 6, with two rows called x
- Create a matrix for the sequence 2 through 7, with two rows called y
- Bind the columns of y to x
- Bind the rows of y to x
Back
x=3:8
matrix(x,ncol=2)
Front
- Create a sequence from 3 to 8 with increment of 1
- Create matrix with 2 columns, number of rows dependent on the number of values
- Concatenate this string of values and call it data
- Convert it to a matrix named country.data with 3 rows, filling by the row instead of column
Back
dimnames(country.data)=list(countries,variables)
Front
- Assign the previously created row and column names to the data
-First list value is row name, second is column name
Back
rep(3,5)
Front
- Create a matrix of value 3, repeated 5 times
3 3 3 3 3
Back
dimnames(country.data)
Front
- Show dimension names
Back
variables=c("GDP", "POP", "Inflation")
Front
- List of column names for GDP, population, and inflation
Back
x=seq(1,20,5)
x>7
indx=x>10
Front
- Create sequence 1 to 20 in increments of 5
- True/False statements for values greater than 7 for the sequence
-
Back
country.data[2,3]
Front
- What is the value of the second row and the third column?
Back
x=3:8
matrix(x)
Front
- Create a sequence from 3 to 8 with increment of 1
- Create matrix of sequence (one column)
Back
x=rnorm(100)
plot(x,pnorm(x))
plot(x,dnorm(x))
Front
- Generate 100 random numbers
- Plot the distribution function
- Plot the density function
Back
country.data[2,]
country.data[,2]
Front
- Show all data in row 2
- Show all data in column 2
Back
country.data[1,2]=10
Front
- Replace the value in the first row and second column with 10
Back
for (i in 1:1000) y=c(y,mean(rnorm(100)))
hist(y)
Front
- Generate 100 random numbers and calculate the mean, 1000 times
- Plot the histogram
Back
x=seq(-5,25,length.out=50)
Front
- Sequence from -5 to 25 with 50 uniform increments
Back
rep(c(1,2,3),2)
Front
- Concatenate values 1, 2, and 3, and repeat it twice
1 2 3 1 2 3
Back
rowMeans(country.data)
Front
- Calculate the mean for each row of data
Back
x=1:10
y=2:11
x+y
x*y
x %% y
Front
- Create sequence called x from 1 to 10 in increments of 1
- Create sequence called y from 2 to 11 in increments of 1
- Add all matching x and y elements
- Multiply all matching x and y elements
- Multiply the two elements using matrix math (dot product)
Back
x=-5:25
Front
- Same thing, creates sequence -5 to 25 in increments of 1
Back
x<-c(1,20,5)
x[x>10]
sum(x[x>10])
Front
- Create sequence 1 to 20 in increments of 5
- Select elements of x greater than 10
- Add up elements of x greater than 10
Back
x=seq(-5,25,2)
Front
- Sequence from -5 to 25 in increments of 2
Back
x=3:8
matrix(c,ncol=3,byrow=T)
Front
- Create a sequence from 3 to 8 with increment of 1
- Create a matrix with 3 columns, with sequence increasing by row and not by columns
- Create a list of character strings
- Add the list to the data frame
Back
x=3:8
matrix(x,3,2)
Front
- Create a sequence from 3 to 8 with increment of 1
- Create matrix with 3 rows and 2 columns
Back
x=c(1,3,5)
Front
Creates matrix:
x = 1 3 5
Back
x=1:10
y=20:30
z=c(x,y)
Front
- Create sequence called x from 1 to 10 in increments of 1
- Create sequence called y from 20 to 30 in increments of 1
- Concatenate the two into a sequence called z
Back
apply(country.data,2,max)
Front
- Compute the maximum values in each column
Back
countries=c("austria", "france", "germany")
Front
- Create a list of row names for Austria, France, and Germany