1. Make a vector from 1 to 100. Make a for-loop which runs through the whole vector. Multiply the elements which are smaller than 5 and larger than 90 with 10 and the other elements with 0.1.

Algebra & Trigonometry with Analytic Geometry
13th Edition
ISBN:9781133382119
Author:Swokowski
Publisher:Swokowski
Chapter10: Sequences, Series, And Probability
Section10.7: Distinguishable Permutations And Combinations
Problem 30E
Question
2:34 PMⒸ
6.2. CONDITIONAL STATEMENTS
STATISTICAL PROGRAMMING I
Lab Exercise: #1
DO
DO
Tools
..
1. Make a vector from 1 to 100. Make a for-loop which runs through the whole vector. Multiply
the elements which are smaller than 5 and larger than 90 with 10 and the other elements
with 0.1.
(a) for (i in 1:2) print (i)
(b) for (i in (1:4)-2) print (i)
2. Write a short program that reports the absolute value of every element in a vector, v. Hint:
the number of elements in a vector v can be obtained by length (v)
3. Write a short program that reports "PASS" for exam marks >= 40 or "FAIL" for exam marks
< 40. Put the exam marks in a vector called "exam".
4. Write a program using a for loop to sum the integers 1 to 10.
5. Write some lines of R code that will calculate the sum 1+2+3+...+300, using a for loop.
6. Write an R code to compute the factorial for an integer x.
7. Write an R code using a for loop for printing the square root of the integers one to 100.
8. The following R codes might be having some error(s). Correct the error(s) and write the
expected output of the following R code:
(c) a 1:10
b=NULL
for(i in seq(along=a))
{ if (a[i]<5 || a[i]>8} {b=c(b, a[i]) } else {
stop ("values need to be <5") } }
(e) rm(list())
a 1:10
(d) rm(list())
a=1:10
b=NULL
for (i in seq(along=a))
{ if (a[i]<5|| a[i]>8} {b-c (b, a[i]) } else
{ break ("values need to be <5") } }
.ıll.
(f) y=log (c(3, 0.5, 2, 4))
ifelse (y<0, NA, y)
b=NULL
for (i in seq(along=a))
{ if (a[i]<5 || a[i]>8} {b=c(b, a[i]) } {else{next}}
b
• if statement
• warning messages
6.2. CONDITIONAL STATEMENTS
49
9. A geometric progression is defined by the recursive relation an = ran-1. Write an R
program that gives the geometric progression. Don't forget to use:
Mobile View
10. Use repeat, next and break to print the odd integers between 1 and 10. Re
exercise using while, instead of repeat, and print the even integers.
11. Generate the following four vectors of length 100.
(a) For each column, the average of all 1,000 observations in that column.
18
Share
W
PDF to DOC
77
x
心
Edit on PC
Transcribed Image Text:2:34 PMⒸ 6.2. CONDITIONAL STATEMENTS STATISTICAL PROGRAMMING I Lab Exercise: #1 DO DO Tools .. 1. Make a vector from 1 to 100. Make a for-loop which runs through the whole vector. Multiply the elements which are smaller than 5 and larger than 90 with 10 and the other elements with 0.1. (a) for (i in 1:2) print (i) (b) for (i in (1:4)-2) print (i) 2. Write a short program that reports the absolute value of every element in a vector, v. Hint: the number of elements in a vector v can be obtained by length (v) 3. Write a short program that reports "PASS" for exam marks >= 40 or "FAIL" for exam marks < 40. Put the exam marks in a vector called "exam". 4. Write a program using a for loop to sum the integers 1 to 10. 5. Write some lines of R code that will calculate the sum 1+2+3+...+300, using a for loop. 6. Write an R code to compute the factorial for an integer x. 7. Write an R code using a for loop for printing the square root of the integers one to 100. 8. The following R codes might be having some error(s). Correct the error(s) and write the expected output of the following R code: (c) a 1:10 b=NULL for(i in seq(along=a)) { if (a[i]<5 || a[i]>8} {b=c(b, a[i]) } else { stop ("values need to be <5") } } (e) rm(list()) a 1:10 (d) rm(list()) a=1:10 b=NULL for (i in seq(along=a)) { if (a[i]<5|| a[i]>8} {b-c (b, a[i]) } else { break ("values need to be <5") } } .ıll. (f) y=log (c(3, 0.5, 2, 4)) ifelse (y<0, NA, y) b=NULL for (i in seq(along=a)) { if (a[i]<5 || a[i]>8} {b=c(b, a[i]) } {else{next}} b • if statement • warning messages 6.2. CONDITIONAL STATEMENTS 49 9. A geometric progression is defined by the recursive relation an = ran-1. Write an R program that gives the geometric progression. Don't forget to use: Mobile View 10. Use repeat, next and break to print the odd integers between 1 and 10. Re exercise using while, instead of repeat, and print the even integers. 11. Generate the following four vectors of length 100. (a) For each column, the average of all 1,000 observations in that column. 18 Share W PDF to DOC 77 x 心 Edit on PC
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Algebra & Trigonometry with Analytic Geometry
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:
9781133382119
Author:
Swokowski
Publisher:
Cengage