In: Statistics and Probability
How do I input this in R studio
1. Combine the following lists into a matrix called animals, where each list becomes a row:
Cats = 2,2,4
Dogs = 1,2,1
Cows = 30,35,41
2. Add column names of “Farm A”, Farm B”, and “Farm C”.
3. Transpose the rows and columns in animals and store the result to a matrix called farms.
4. Display the contents of farms.
The R output
COMMANDS are given
below
#we have 3 lists
cats=list(2,2,4)
dogs=list(1,2,1)
cows=list(30,35,41)
#1. Combine lists into a matrix called animals, where each list
becomes a row
animals=rbind(cats, dogs, cows); animals
#2 Add column names
colnames(animals)<- c("Farm A", "Farm B", "Farm C"); animals
#3. Taking transpose and storing it into farms
farms=t(animals)
#4. displaying the contents of farms
farms