a) how to find length of vector CODE: vtr =c(2,4,5,6,7,1,10) vl = length(vtr) print("Vector length:") print(vl) b) to sort the vector in decreasing order CODE: vtr =c(2,4,5,6,7,1,10) #sort in decreasing order sort(vtr, decreasing=TRUE) c) to replace the third index value with 9 CODE: vtr =c(2,4,5,6,Read more
a) how to find length of vector
CODE:vtr =c(2,4,5,6,7,1,10)vl = length(vtr)print("Vector length:")print(vl)
b) to sort the vector in decreasing order
CODE:vtr =c(2,4,5,6,7,1,10)#sort in decreasing ordersort(vtr, decreasing=TRUE)
c) to replace the third index value with 9
CODE:vtr =c(2,4,5,6,7,1,10)r1<-replace(vtr,3,"9")print(r1)
d) to add one more element at the end of vector.
CODE:vtr =c(2,4,5,6,7,1,10)addnew<-append(vtr,40)print(addnew)
e) To print all elements except first element of a vector.
CODE:vtr =c(2,4,5,6,7,1,10)new<-vtr[-1]print(new)
#include <stdio.h> int main() { int n, i; unsigned long long fact = 1; printf("Enter an integer: "); scanf("%d", &n); // shows error if the user enters a negative integer if (n < 0) printf("Error! Factorial of a negative number doesn't exist."); elseRead more
#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
// shows error if the user enters a negative integer
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %llu", n, fact);
}
return 0;
}
a) To concatenate two strings with syntax sol:cat(st1, st2,sep = ' ') b) To find out the minimum valued index number sol:which.min(x) c) To sort a particular column of a dataset sol: arrange(dataframe,column) d) To check inbuilt datasets in r. sol:data() e) To check the data type of any variaRead more
Question 1) A break statement is used inside a loop (repeat, for, while) to stop the iterations and flow the control outside of the loop. The syntax of break statement is: if (test_expression) { break } A next statement is useful when we want to skip the current iteration of a loop without terminatiRead more
Question 1)
A break statement is used inside a loop (repeat, for, while) to stop the iterations and flow the control outside of the loop.
The syntax of break statement is:
if (test_expression) {
break
}
A next statement is useful when we want to skip the current iteration of a loop without terminating it. On encountering next the R parser skips further evaluation and starts next iteration of the loop.
The syntax of next statement is:
if (test_condition) {
next
}Question 2)
row_names = c("row1", "row2", "row3", "row4")
col_names = c("col1", "col2", "col3", "col4")
M = matrix(c(1:16), nrow = 4, byrow = TRUE, dimnames = list(row_names, col_names))
print("Original Matrix:")
print(M)
print("Access the element at 3rd column and 2nd row:")
print(M[2,3])
print("Access only the 3rd row:")
print(M[3,])
print("Access only the 4th column:")
print(M[,4])
Question 3)
R has 6 basic data types.
character
numeric (real or decimal)
integer
logical
complex
R’s basic data structures include the vector, list, matrix, data frame, and factors. Some of these structures require that all members be of the same data type (e.g. vectors, matrices) while others permit multiple data types (e.g. lists, data frames).
1) Armstrong number: A number is thought of as an Armstrong number if the sum of its own digits raised to the power number of digits gives the number itself. For example, 0, 1, 153, 370, 371, 407 are three-digit Armstrong numbers and, 1634, 8208, 9474 are four-digit Armstrong numbers and there are mRead more
1) Armstrong number: A number is thought of as an Armstrong numberif the sum of its own digits raised to the power number of digits gives the number itself.
For example, 0, 1, 153, 370, 371, 407 are three-digit Armstrong numbers and, 1634, 8208, 9474 are four-digit Armstrong numbers and there are many more.
EXAMPLE:Let’s consider 370 since it is a three-digit number so it could be expressed as: (3*3*3)+(7*7*7)+(0*0*)= 27 +343+0 =370
CODE For Armstrong number:
{
num = as.integer(readline(prompt = "Enter a number :"))
rv = 0
temp = num
while (num > 0) {
r = num %% 10
rv = rv + r * r * r
num= num %/% 10
}
if (rv == temp)
{
print(paste("Number is Armstrong :", rv))
}
else{
print(paste("Number is not Armstrong :", rv))
}
}
What will be the output of the following R code? * m <- matrix( nrow = 2, ncol = 3) …
OUTPUT : 2 3
OUTPUT : 2 3
See lessvector is given: vtr =c(2,4,5,6,7,1,10) a) how to find length of vector b) to sort the vector in decreasing order …
a) how to find length of vector CODE: vtr =c(2,4,5,6,7,1,10) vl = length(vtr) print("Vector length:") print(vl) b) to sort the vector in decreasing order CODE: vtr =c(2,4,5,6,7,1,10) #sort in decreasing order sort(vtr, decreasing=TRUE) c) to replace the third index value with 9 CODE: vtr =c(2,4,5,6,Read more
Write a program to find the factorial of a number using function in C.
#include <stdio.h> int main() { int n, i; unsigned long long fact = 1; printf("Enter an integer: "); scanf("%d", &n); // shows error if the user enters a negative integer if (n < 0) printf("Error! Factorial of a negative number doesn't exist."); elseRead more
Write the function names for a) To concatenate two strings with syntax b) To find out the minimum valued index …
a) To concatenate two strings with syntax sol:cat(st1, st2,sep = ' ') b) To find out the minimum valued index number sol:which.min(x) c) To sort a particular column of a dataset sol: arrange(dataframe,column) d) To check inbuilt datasets in r. sol:data() e) To check the data type of any variaRead more
a) To concatenate two strings with syntax
sol:cat(st1, st2,sep = ‘ ‘)
b) To find out the minimum valued index number
sol:which.min(x)
c) To sort a particular column of a dataset
sol: arrange(dataframe,column)
d) To check inbuilt datasets in r.
sol:data()
e) To check the data type of any variable.
sol:typeof(x)
See less1)Differentiate between next and break with example. 2)Write a R program to access the element at 3rd column and 2nd …
Question 1) A break statement is used inside a loop (repeat, for, while) to stop the iterations and flow the control outside of the loop. The syntax of break statement is: if (test_expression) { break } A next statement is useful when we want to skip the current iteration of a loop without terminatiRead more
1)Write a R code for armstrong number 2)What will be the output of the following R code? x <- c(“a”, …
1) Armstrong number: A number is thought of as an Armstrong number if the sum of its own digits raised to the power number of digits gives the number itself. For example, 0, 1, 153, 370, 371, 407 are three-digit Armstrong numbers and, 1634, 8208, 9474 are four-digit Armstrong numbers and there are mRead more
1) Armstrong number: A number is thought of as an Armstrong number if the sum of its own digits raised to the power number of digits gives the number itself.
For example, 0, 1, 153, 370, 371, 407 are three-digit Armstrong numbers and, 1634, 8208, 9474 are four-digit Armstrong numbers and there are many more.
EXAMPLE:Let’s consider 370 since it is a three-digit number so it could be expressed as: (3*3*3)+(7*7*7)+(0*0*)= 27 +343+0 =370
CODE For Armstrong number:
2)Output of Following code will be
“a”
“b”
“c”
“d”
See less