SlideShare a Scribd company logo
1 of 6
Download to read offline
BASIC COURSE IN R
Exercises
a) Create a vector x that contains the values (1 2 3 4) and a
vector y that contains the values (-1 1). Concatenate x and
y and store the result as z. Print it.
b) Create a vector s as the sum of x and y. Print s. For every
entry in s, explain how R has computed it.
c) What happens if you compute the sum of x and z? Explain
why.
Task 1
a) Create a vector u which contains all integers from 1 to 100
b) Create a vector x which contains the elements of u which are
not a multiple of 3.
c) Create a vector y which contains the elements of u which are
neither divisible by 2, nor by 3, neither by 5.
d) Create a vector z replacing all elements from u that are less
than 55 by the number 0.
Task 2
Create the following matrix as efficiently as possible and store the
matrix as P.
Task 3
Using the matrix P from the previous task:
a) Print the first row and the second column of P.
b) Print the submatrix that consists of the last three rows and
first two columns of P.
c) Replace the fourth row of P by (1, 2, 3, 4, 5).
d) Replace all nonzero entries of the matrix P by 1.
Task 4
With the dataset swiss, create a data frame with only the rows
1, 2, 3, 10, 11, 12 and 13, and only the variables
Examination, Education and Infant.Mortality and call
it t11.
a) The infant mortality of Sarine is wrong, it should be an NA, change
it.
b) Create a row that will be the total sum of the column, name it
Total.
c) Create a new variable that will be the proportion of
Examination (Examination / Total)
Task 5

More Related Content

Similar to Exercises2.pdf

Nbhm m. a. and m.sc. scholarship test 2005
Nbhm m. a. and m.sc. scholarship test 2005Nbhm m. a. and m.sc. scholarship test 2005
Nbhm m. a. and m.sc. scholarship test 2005MD Kutubuddin Sardar
 
Due Week 10 and worth 250 pointsIn preparation for this assignme.docx
Due Week 10 and worth 250 pointsIn preparation for this assignme.docxDue Week 10 and worth 250 pointsIn preparation for this assignme.docx
Due Week 10 and worth 250 pointsIn preparation for this assignme.docxjacksnathalie
 
Nbhm m. a. and m.sc. scholarship test 2007
Nbhm m. a. and m.sc. scholarship test 2007 Nbhm m. a. and m.sc. scholarship test 2007
Nbhm m. a. and m.sc. scholarship test 2007 MD Kutubuddin Sardar
 
Ee693 questionshomework
Ee693 questionshomeworkEe693 questionshomework
Ee693 questionshomeworkGopi Saiteja
 
Final exam g8 2014
Final exam g8 2014Final exam g8 2014
Final exam g8 2014zeinabze
 
Nbhm m. a. and m.sc. scholarship test 2010
Nbhm m. a. and m.sc. scholarship test 2010Nbhm m. a. and m.sc. scholarship test 2010
Nbhm m. a. and m.sc. scholarship test 2010MD Kutubuddin Sardar
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.pptjvjfvvoa
 
Nbhm m. a. and m.sc. scholarship test 2006
Nbhm m. a. and m.sc. scholarship test 2006Nbhm m. a. and m.sc. scholarship test 2006
Nbhm m. a. and m.sc. scholarship test 2006MD Kutubuddin Sardar
 
Travaux Pratique Matlab + Corrige_Smee Kaem Chann
Travaux Pratique Matlab + Corrige_Smee Kaem ChannTravaux Pratique Matlab + Corrige_Smee Kaem Chann
Travaux Pratique Matlab + Corrige_Smee Kaem ChannSmee Kaem Chann
 
Ee693 sept2014quizgt2
Ee693 sept2014quizgt2Ee693 sept2014quizgt2
Ee693 sept2014quizgt2Gopi Saiteja
 
1. (5 pts) Which of these graphs represent a one-to-one function .docx
1. (5 pts) Which of these graphs represent a one-to-one function .docx1. (5 pts) Which of these graphs represent a one-to-one function .docx
1. (5 pts) Which of these graphs represent a one-to-one function .docxlindorffgarrik
 

Similar to Exercises2.pdf (20)

Nbhm m. a. and m.sc. scholarship test 2005
Nbhm m. a. and m.sc. scholarship test 2005Nbhm m. a. and m.sc. scholarship test 2005
Nbhm m. a. and m.sc. scholarship test 2005
 
algo1
algo1algo1
algo1
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Due Week 10 and worth 250 pointsIn preparation for this assignme.docx
Due Week 10 and worth 250 pointsIn preparation for this assignme.docxDue Week 10 and worth 250 pointsIn preparation for this assignme.docx
Due Week 10 and worth 250 pointsIn preparation for this assignme.docx
 
Veena vtext
Veena vtextVeena vtext
Veena vtext
 
Veena vtext
Veena vtextVeena vtext
Veena vtext
 
Nbhm m. a. and m.sc. scholarship test 2007
Nbhm m. a. and m.sc. scholarship test 2007 Nbhm m. a. and m.sc. scholarship test 2007
Nbhm m. a. and m.sc. scholarship test 2007
 
Ee693 questionshomework
Ee693 questionshomeworkEe693 questionshomework
Ee693 questionshomework
 
Final exam g8 2014
Final exam g8 2014Final exam g8 2014
Final exam g8 2014
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Nbhm m. a. and m.sc. scholarship test 2010
Nbhm m. a. and m.sc. scholarship test 2010Nbhm m. a. and m.sc. scholarship test 2010
Nbhm m. a. and m.sc. scholarship test 2010
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
 
A02
A02A02
A02
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.ppt
 
Nbhm m. a. and m.sc. scholarship test 2006
Nbhm m. a. and m.sc. scholarship test 2006Nbhm m. a. and m.sc. scholarship test 2006
Nbhm m. a. and m.sc. scholarship test 2006
 
Travaux Pratique Matlab + Corrige_Smee Kaem Chann
Travaux Pratique Matlab + Corrige_Smee Kaem ChannTravaux Pratique Matlab + Corrige_Smee Kaem Chann
Travaux Pratique Matlab + Corrige_Smee Kaem Chann
 
Ee693 sept2014quizgt2
Ee693 sept2014quizgt2Ee693 sept2014quizgt2
Ee693 sept2014quizgt2
 
Algebreviewer
AlgebreviewerAlgebreviewer
Algebreviewer
 
Algebreviewer
AlgebreviewerAlgebreviewer
Algebreviewer
 
1. (5 pts) Which of these graphs represent a one-to-one function .docx
1. (5 pts) Which of these graphs represent a one-to-one function .docx1. (5 pts) Which of these graphs represent a one-to-one function .docx
1. (5 pts) Which of these graphs represent a one-to-one function .docx
 

Recently uploaded

Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡anilsa9823
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSérgio Sacani
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfSumit Kumar yadav
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxgindu3009
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxBroad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxjana861314
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...jana861314
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxAleenaTreesaSaji
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptxRajatChauhan518211
 

Recently uploaded (20)

Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxBroad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptx
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptx
 

Exercises2.pdf

  • 1. BASIC COURSE IN R Exercises
  • 2. a) Create a vector x that contains the values (1 2 3 4) and a vector y that contains the values (-1 1). Concatenate x and y and store the result as z. Print it. b) Create a vector s as the sum of x and y. Print s. For every entry in s, explain how R has computed it. c) What happens if you compute the sum of x and z? Explain why. Task 1
  • 3. a) Create a vector u which contains all integers from 1 to 100 b) Create a vector x which contains the elements of u which are not a multiple of 3. c) Create a vector y which contains the elements of u which are neither divisible by 2, nor by 3, neither by 5. d) Create a vector z replacing all elements from u that are less than 55 by the number 0. Task 2
  • 4. Create the following matrix as efficiently as possible and store the matrix as P. Task 3
  • 5. Using the matrix P from the previous task: a) Print the first row and the second column of P. b) Print the submatrix that consists of the last three rows and first two columns of P. c) Replace the fourth row of P by (1, 2, 3, 4, 5). d) Replace all nonzero entries of the matrix P by 1. Task 4
  • 6. With the dataset swiss, create a data frame with only the rows 1, 2, 3, 10, 11, 12 and 13, and only the variables Examination, Education and Infant.Mortality and call it t11. a) The infant mortality of Sarine is wrong, it should be an NA, change it. b) Create a row that will be the total sum of the column, name it Total. c) Create a new variable that will be the proportion of Examination (Examination / Total) Task 5