Practical No. 1: Using R execute the basic commands, array, list and frames
I] List:
Script:
a<-list("Naresh",1.2,TRUE,c(3,5))
Output:
> a
[[1]]
[1] "Naresh"
[[2]]
[1] 1.2
[[3]]
[1] TRUE
[[4]]
[1] 3 5
Script:
names(a)<-c("This is a string","This is float","This is Boolian","This is a vector")
Output:
> a
$`This is a string`
[1] "Naresh"
$`This is float`
[1] 1.2
$`This is Boolian`
[1] TRUE
$`This is a vector`
[1] 3 5
Script:
list1<-list(1,2,3,4)
list2<-list("x","y","z")
m_list<-c(list1,list2)
Output:
> m_list
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
[[4]]
[1] 4
[[5]]
[1] "x"
[[6]]
[1] "y"
[[7]]
[1] "z"
II] Array:
One-dimensional array:
Script:
vect<-c(1,2,3,4)
Output:
> vect
[1] 1 2 3 4
Two-dimensional array:
Script:
row_names<-c("Row_1","Row_2")
column_names<-c("column_1","column_2")
mat_names<-c("Matrix_1","Matrix_2")
arr= array(1:10, dim = c(2,2,2), dimnames = list(row_names,column_names,mat_names))
Output:
> arr
, , Matrix_1
    column_1   column_2
Row_1Â Â Â 1Â Â Â Â Â Â Â 3
Row_2Â Â Â 2Â Â Â Â Â Â Â 4
, , Matrix_2
    column_1   column_2
Row_1Â Â Â 5Â Â Â Â Â Â Â 7
Row_2Â Â Â 6Â Â Â Â Â Â Â 8
> arr[, , 1]
    column_1   column_2
Row_1Â Â Â 1Â Â Â Â Â Â Â 3
Row_2Â Â Â 2Â Â Â Â Â Â Â 4
> arr[, , 2]
    column_1   column_2
Row_1Â Â Â Â 5Â Â Â Â Â Â Â 7
Row_2Â Â Â 6Â Â Â Â Â Â Â 8
> arr[1, , 1]
   column_1   column_2
     1       3
> arr[1, 1, 1]
[1] 1
> arr[1, 1, 2]
[1] 5
III] Data Frame:
Script:
data.frame(
Training = c("Strength","Stamina","Other"),
Pulse = c(100,150,120),
Duration = c(60,30,45))
Output:
> data.frame(
+ Training = c("Strength","Stamina","Other"),
+ Pulse = c(100,150,120),
+ Duration = c(60,30,45))
   Training  Pulse Duration
1   Strength  100  60
2   Stamina   150  30
3   Other   120  45
Script:
Health_Data<-data.frame(
Training = c("Strength","Stamina","Other"),
Pulse = c(100,150,120),
Duration = c(60,30,45))
Output:
> Health_Data
  Training  Pulse Duration
1  Strength  100  60
2  Stamina   150  30
3  Other   120  45
Script:
str(Health_Data)
Output:
> str(Health_Data)
'data.frame': 3 obs. of 3 variables:
$ Training: chr "Strength" "Stamina" "Other"
$ Pulse : num 100 150 120
$ Duration: num 60 30 45
Script:
summary(Health_Data)
Output:
> summary(Health_Data)
Training       Pulse     Duration
Length:3Â Â Â Â Â Min. :100.0Â Â Â Min. :30.0
Class :character 1st Qu.:110.0  1st Qu.:37.5
Mode :character  Median :120.0  Median :45.0
Mean :123.3Â Â Â Mean :45.0
3rd Qu.:135.0Â Â 3rd Qu.:52.5
Max. :150.0Â Â Â Max. :60.0