Experiment 1

1. Create a data frame in R with following columns: Sl.No, Roll.no, Name, Gender, SSC percentage, Inter percentage, BTech percentage, CAPnotCAP. And fill at least 5 rows of your choice.

# Let's make the vectors first.
Sl_no <- c(1, 2, 3,4 ,5)
roll_No <- c(6, 22,49,54,60)
Name <- c("Abhi", "Balu", "Charan", "Durga", "Ram")
Gender <- c("M", "M", "M", "F", "M")
SSC_percentage <- c(85.3,78.4,67.5,79.6,62.7)
B_Tech_percentage <- c(67.4,75.5,79.6,67.7,78.8)
Cap_notcap <- c(FALSE, TRUE, FALSE, TRUE, FALSE)
# Now prepare the data frames from the vectors
df <- data.frame(Sl_no, roll_No, Name, Gender, SSC_percentage, B_Tech_percentage,    Cap_notcap)
print(df)
##   Sl_no roll_No   Name Gender SSC_percentage B_Tech_percentage Cap_notcap
## 1     1       6   Abhi      M           85.3              67.4      FALSE
## 2     2      22   Balu      M           78.4              75.5       TRUE
## 3     3      49 Charan      M           67.5              79.6      FALSE
## 4     4      54  Durga      F           79.6              67.7       TRUE
## 5     5      60    Ram      M           62.7              78.8      FALSE

2a. What is the structure of dataframe?

str(df)
## 'data.frame':    5 obs. of  7 variables:
##  $ Sl_no            : num  1 2 3 4 5
##  $ roll_No          : num  6 22 49 54 60
##  $ Name             : Factor w/ 5 levels "Abhi","Balu",..: 1 2 3 4 5
##  $ Gender           : Factor w/ 2 levels "F","M": 2 2 2 1 2
##  $ SSC_percentage   : num  85.3 78.4 67.5 79.6 62.7
##  $ B_Tech_percentage: num  67.4 75.5 79.6 67.7 78.8
##  $ Cap_notcap       : logi  FALSE TRUE FALSE TRUE FALSE

2b. What are the names of the columns in the dataframe?

colnames(df)
## [1] "Sl_no"             "roll_No"           "Name"             
## [4] "Gender"            "SSC_percentage"    "B_Tech_percentage"
## [7] "Cap_notcap"

2c. What is the datatype of all attributes?

sapply(df, class)
##             Sl_no           roll_No              Name            Gender 
##         "numeric"         "numeric"          "factor"          "factor" 
##    SSC_percentage B_Tech_percentage        Cap_notcap 
##         "numeric"         "numeric"         "logical"

3.a Write R code to display only SSC percentage.

df$SSC_percentage
## [1] 85.3 78.4 67.5 79.6 62.7

3.b Write R code to display the second row.

df[2,]
##   Sl_no roll_No Name Gender SSC_percentage B_Tech_percentage Cap_notcap
## 2     2      22 Balu      M           78.4              75.5       TRUE

3c. Write R code to display only SSC percentage and Inter percentage.

df[,c(5,6)]
##   SSC_percentage B_Tech_percentage
## 1           85.3              67.4
## 2           78.4              75.5
## 3           67.5              79.6
## 4           79.6              67.7
## 5           62.7              78.8

3d.What is the B.tech_percentage of 4th entry.

df[4,6]
## [1] 67.7

4. Find out minimum, maximum, mean percentage of all B.Tech students.

paste("The minimum value is",min(df$B_Tech_percentage))
## [1] "The minimum value is 67.4"
paste("The maximum value is",max(df$B_Tech_percentage))
## [1] "The maximum value is 79.6"
paste("The mean value is",mean(df$B_Tech_percentage))
## [1] "The mean value is 73.8"