You are on page 1of 2

BRM -Part B

1. The C function combines the values into a vector or list in which all the values except names
are returned .
Example: c(list(A = c(B = 1)), recursive = TRUE)
The rep function is a replication function which replicates the values in X. It is a generic
function.
Example: rep(x, times = 1, length.out = NA, each = 1)
The seq function is the sequence generation function in R. It is a bit primitive but also works
fast.
Example: seq(from, to)
The data frame function combines many data frames together in which various variable data
are present such as data of matrices, lists etc.
Example: data.frame(…, row.names = NULL, check.rows = FALSE)

We must use the rbind function to create a new row or observation.


Example: rbind(DataFrame.BIMmarks.Marks, SectionA.Marks)
New column or variable can be used by the following syntax
<Existing Data Frame>$ <Variable/Column Name> <- <Object/Value of Variable>
Eg. Marks$SecAmarks<-(50,55,52)

2. The following steps needs to be followed to import the files from excel to R.
a. Install the readxl package using this command install.packages("readxl")
b. Prepare the excel file which is necessary to be imported in to R
c. Use the following syntax to import the file into R
library("readxl")
read_excel("Path where your Excel file is stored\\File Name.xlsx")

After these steps the Excel file will be imported into R

3. –
4. Control statements in R is used to know the flow of control in the various parts of the
program. These are decision making statements in R.
a. If statement:
This allows the flow if the condition is true.
Example: x < 100

if(x > 10){


print(paste(x, "is greater than 10"))
}

b. Ifelse condition:
Similar to the if condition but redirects to another output if the flow is diverted
Example: if(x > 10){
print(paste(x, "is greater than 10"))
}else{
print(paste(x, "is less than 10"))
}

c. For loop:
It is a continuous loop.
Example: x <- numbers

for(i in x){
print(i)
}

d. Nested Loops:
These are loops within loops
m <- matrix(2:15, 2)

for (r in seq(nrow(m))) {
for (c in seq(ncol(m))) {
print(m[r, c])
}
}

e. While Loop:
This loop can be executed without a condition. It can also run continuously
while(x <= 5){
print(x)
x=x+1
}

You might also like