Sunday, December 22, 2024

SYBScIT (Information Technology) Computer Oriented Statistical Techniques Practical Manual with Solutions in R

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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

2,523FansLike
246FollowersFollow
2,458FollowersFollow

Most Popular

Recent Comments