df =read.csv(file="marks1.csv", head=TRUE, sep=",")
dim() shows the dimensions of the data frame by row and column.
dim(df)
## [1] 11 10
head() returns the first n rows (observe the index values)
head(df)
tail() returns the last n rows (observe the index values)
tail(df)
summary() provides summary data related to the individual object that was fed into it.
options(width=100) # for adjusting the output
summary(df)
## X X.1 test asgn Prsnt Final
## Min. :60001 Length:11 Min. :12.00 Min. :10.00 Min. :12.00 Min. :12.00
## 1st Qu.:60007 Class :character 1st Qu.:17.00 1st Qu.:13.00 1st Qu.:17.00 1st Qu.:17.00
## Median :60011 Mode :character Median :21.00 Median :14.00 Median :18.00 Median :22.00
## Mean :60013 Mean :21.45 Mean :13.55 Mean :17.45 Mean :20.18
## 3rd Qu.:60019 3rd Qu.:25.50 3rd Qu.:15.00 3rd Qu.:19.00 3rd Qu.:23.00
## Max. :60026 Max. :30.00 Max. :15.00 Max. :19.00 Max. :28.00
## q1 q2 q3 q4
## Min. :0.000 Min. :3.000 Min. :1.000 Min. : 4.000
## 1st Qu.:2.000 1st Qu.:5.000 1st Qu.:4.000 1st Qu.: 5.000
## Median :3.000 Median :5.000 Median :5.000 Median : 6.000
## Mean :3.136 Mean :5.818 Mean :5.091 Mean : 6.409
## 3rd Qu.:4.000 3rd Qu.:7.000 3rd Qu.:6.500 3rd Qu.: 7.750
## Max. :6.000 Max. :9.000 Max. :9.000 Max. :10.000
colnames() shows the name of each column in the data frame
colnames(df)
## [1] "X" "X.1" "test" "asgn" "Prsnt" "Final" "q1" "q2" "q3" "q4"
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.2
## -- Attaching packages ----------------------------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.5 v dplyr 1.0.7
## v tidyr 1.1.4 v stringr 1.4.0
## v readr 2.1.0 v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.1.2
## Warning: package 'readr' was built under R version 4.1.2
## -- Conflicts -------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
df = df %>% rename(ID = X, StuName = X.1 )
head(df)
df = subset(df, select = -c(ID,StuName))
head(df)
#Total = rowSums(df)
Total = apply(df,1,sum) # sum of all their marks
print(Total)
## 1 2 3 4 5 6 7 8 9 10 11
## 74 101 105 80 96 96 120 90 93 110 59
df <- cbind(df,Total)
head(df)
column_range_1=function(x,y){
cw = apply(df[x:y],1,sum)
return(cw)
}
#another method used
column_range_2=function(x,y){
cw=rowSums(df[x:y], na.rm=TRUE)
return(cw)
}
calling the function and naming the column CW
df <- cbind(df,CW=column_range_1(1,3))
df