-
Notifications
You must be signed in to change notification settings - Fork 0
/
Questions.R
111 lines (61 loc) · 2.12 KB
/
Questions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Questions on Loops
Q1
given two vectors v1 and v2'
v1 <- seq(1,15,2)
v2 <- seq(2,16,2)
arrange assign to a vector such that alternative elements of v1 and v2 are stacked up
example v3 = c(1,2,3,4,5.....)
Q2
given a vector v1 create a vector v2 having the elements of v1 in forward and reverse order
input: v1 = c(1,3,7)
output: v2 = c(1,3,7,7,3,1)
Q3:
Check if the number is even or odd?
x = 26
Output: "Number is a even number"
Q4
given a number check if the number is a prime or composite number
input : 15
output : "number is composite"
Q5:
given a number list all the prime factors of the number
input : 24
output : 2,3
Q6:
Check if the given word is a palindrome or not
Input : noon
Output: "is a palindrome"
Q5
Advanced:
convert a given integer number into binary
#Questions on functions
#Q1 :
Wrap the prime number checker into a function
#Q2:
Wrap the prime factors generator into a function and return a vector of all the prime factors
#Q3:
Write a function to searh for an element in entire data frame and return True or False if found
#Q4:
Extend the above function to get the row and column of the instance found
#Q5:
Write a function to delete every third instance in a vector and return the modefied vector
input : Vector v1
output : Modified Vector v2
#Q6:
Given a numeric v1 return sum of all the elements raised to the power of the elements positions
in reverse order
example : v1 = c(1,2,3)
Output : 8 i.e (1^3+2^2+3^1)
#Q7:
Write a function to splict string into characters
#Q7:
In a vector of strings search for a word occurance and return a vector with Found and NotFound
inputs : vector of Strings, search word
example: v1 = c("Is it True", "R is amazing","Very much")
search word : "is"
Output: c("Found","Found","Not Found")
#Q8:
Advanced:
Remove all redundant spaces if any in a vector of strings
Input : c("Hello World","I have two spaces in between" "This is correct spacing")
Output: c("Hello World","I have two spaces in between","This is correct spacing")