R Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

R programming

Commands
VECTOR
#Vector Indexing
X=c (3,6,4,2,5)
X
#2nd component of X
#1st and third components of X
#All of X except 1st components
#All of X except 1st two components
Assign 7.1 and 3.4 values to first two components of X
#All of X except first and fourth component

X[2]
X[c(1,3)]
X[-1]
X[-1:-2]
X[1:2] = c(7.1,3.4)
X

MATRIX

#Elements are arranged sequentially by row


M <- matrix(c(3:14), nrow = 4, byrow = TRUE)
print (M)

#Elements are arranged sequentially by row


M = matrix(c(3:14), nrow = 4, byrow = TRUE)
print (M)

#Elements are arranged sequentially by row


N <- matrix(c(3:14), nrow = 4, byrow = FALSE)
print (N)

#Define the column and row names


rownames = c("row1", "row2", "row3", "row4")
colnames = c("col1", "col2", "col3")
P <- matrix(c(3:14), nrow = 4, byrow = TRUE,
dimnames = list(rownames, colnames))
print(P)

#Accessing Elements of a Matrix

# Access the element at 3rd column and 1st row.


print(P[1,3])
# Access the element at 2nd column and 4th row.
print(P[4,2])
# Access only the second row.
print(P[2,])
# Access only the 3rd column.
print(P[,3])
#Access More Than One Row
P[c(1,2),]
P[c(1,2),2]
P[c(3,4),-1]
P[c(3,4),c(2,3)]

#Access More Than One Column

#Access More Than One Row and One column


P[c(1,2), c(1,2)]

M = matrix(c(1,2,3,4,5,6),3,3)
M

M = matrix(c(1,2,3,4,5,6,7,8,9),3,3)
M
BY DEFAULT COLUMN WISE ARRANGEMENT OF ROW
M = matrix(c(1,2,3,4,5,6),2,3)
M

M = matrix(c(1,2,3,4,5,6),3,3, byrow = TRUE)


M

#Matrix Addition & Subtraction

#Create two 2X3 matrices

matrix1 <- matrix(c(3, 9, -1, 4, 2, 6), nrow = 2)


print(matrix1)
matrix2 <- matrix(c(5, 2, 0, 9, 3, 1), nrow = 2)
print(matrix2)

#Add the matrices


result <- matrix1 + matrix2
print(result)

matrix1*matrix2
matrix1+matrix2
matrix1-matrix2
matrix1/matrix2

R <- matrix(c(1,2,3,4,5,6), nrow = 3)


R

S <- matrix(c(1,2,3,4,5,6), nrow = 2)


S

R%*%S
MATRIX MULTIPLICATION

R*S
MATRIX ELEMENT MULTIPLICATION

A=matrix(c(1,2,3,4,5,6,7,8,9),3,3)
A
diag(A)
diag(4)

B=diag(A)
diag(B)

Results
#Vector Indexing
> X=c (3,6,4,2,5)
>X
[1] 3 6 4 2 5
> X[2]
[1] 6
> X[c(1,3)]
[1] 3 4
> X[-1]
[1] 6 4 2 5
> X[-1:-2]
[1] 4 2 5
> X[1:2] = c(7.1,3.4)
>X
[1] 7.1 3.4 4.0 2.0 5.0
> X[c(-1,-4)]
[1] 3.4 4.0 5.0
>
> #Elements are arranged sequentially by row
> M <- matrix(c(3:14), nrow = 4, byrow = TRUE)
> print (M)
[,1] [,2] [,3]
[1,] 3 4 5
[2,] 6 7 8
[3,] 9 10 11
[4,] 12 13 14
> #Elements are arranged sequentially by row
> M = matrix(c(3:14), nrow = 4, byrow = TRUE)
> print (M)
[,1] [,2] [,3]
[1,] 3 4 5
[2,] 6 7 8
[3,] 9 10 11
[4,] 12 13 14
> #Elements are arranged sequentially by row
> N <- matrix(c(3:14), nrow = 4, byrow = FALSE)
> print (N)
[,1] [,2] [,3]
[1,] 3 7 11
[2,] 4 8 12
[3,] 5 9 13
[4,] 6 10 14
> P <- matrix(c(3:14), nrow = 4, byrow = TRUE,
+ dimnames = list(rownames, colnames)
+ print (P)
Error: unexpected symbol in:
" dimnames = list(rownames, colnames)
print"
> P <- matrix(c(3:14), nrow = 4, byrow = TRUE,
+ dimnames = list(rownames, colnames))
Error in matrix(c(3:14), nrow = 4, byrow = TRUE, dimnames = list(rownames, :
invalid type (closure) for 'dimnames' (must be a vector)
> print (P)
Error in print(P) : object 'P' not found
> P <- matrix(c(3:14), nrow = 4, byrow = TRUE,
+ dimnames = list(rownames, colnames))
Error in matrix(c(3:14), nrow = 4, byrow = TRUE, dimnames = list(rownames, :
invalid type (closure) for 'dimnames' (must be a vector)
> print(P)
Error in print(P) : object 'P' not found
> #Define the column and row names
> rownames = c("row1", "row2", "row3", "row4")
> colnames = c("col1", "col2", "col3")
> P <- matrix(c(3:14), nrow = 4, byrow = TRUE,
+ dimnames = list(rownames, colnames))
> print(P)
col1 col2 col3
row1 3 4 5
row2 6 7 8
row3 9 10 11
row4 12 13 14
> print(P[1,3])
[1] 5
> print(P[4,2])
[1] 13
> print(P[2,])
col1 col2 col3
6 7 8
> print(p[,3])
Error in print(p[, 3]) : object 'p' not found
> print(P[,3])
row1 row2 row3 row4
5 8 11 14
> P[c(1,2),]
col1 col2 col3
row1 3 4 5
row2 6 7 8
> P[c(1,2),2]
row1 row2
4 7
> P[c(3,4),(2,3)]
Error: unexpected ',' in "P[c(3,4),(2,"
> P[c(3,4),-1]
col2 col3
row3 10 11
row4 13 14
> P[c(3,4),c(2,3)]
col2 col3
row3 10 11
row4 13 14
> P[c(1,2), c(1,2)]
col1 col2
row1 3 4
row2 6 7
> M = matrix(c(1,2,3,4,5,6),3,3)
> M = matrix(c(1,2,3,4,5,6),3,3)
>M
[,1] [,2] [,3]
[1,] 1 4 1
[2,] 2 5 2
[3,] 3 6 3
> M = matrix(c(1,2,3,4,5,6,7,8,9),3,3)
>M
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> M = matrix(c(1,2,3,4,5,6),2,3)
>M
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
> M = matrix(c(1,2,3,4,5,6),3,3, byrow = TRUE)
>M
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 1 2 3
> matrix1 <- matrix(c(3, 9, -1, 4, 2, 6), nrow = 2)
> print(matrix1)
[,1] [,2] [,3]
[1,] 3 -1 2
[2,] 9 4 6
> matrix2 <- matrix(c(5, 2, 0, 9, 3, 1), nrow = 2)
> print(matrix2)
[,1] [,2] [,3]
[1,] 5 0 3
[2,] 2 9 1
> result <- matrix1 + matrix2
> result <- matrix1 + matrix2
> print(result)
[,1] [,2] [,3]
[1,] 8 -1 5
[2,] 11 13 7
> matrix1*matrix2
[,1] [,2] [,3]
[1,] 15 0 6
[2,] 18 36 6
> matrix1+matrix2
[,1] [,2] [,3]
[1,] 8 -1 5
[2,] 11 13 7
> matrix1-matrix2
[,1] [,2] [,3]
[1,] -2 -1 -1
[2,] 7 -5 5
> matrix1/matrix2
[,1] [,2] [,3]
[1,] 0.6 -Inf 0.6666667
[2,] 4.5 0.4444444 6.0000000
> matrix1%*%matrix2
Error in matrix1 %*% matrix2 : non-conformable arguments
> R <- matrix(c(1,2,3,4,5,6), nrow = 3)
>R
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
> S <- matrix(c(1,2,3,4,5,6), nrow = 2)
>S
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
> R%*%S
[,1] [,2] [,3]
[1,] 9 19 29
[2,] 12 26 40
[3,] 15 33 51
> R*S
Error in R * S : non-conformable arrays
> R <- matrix(c(1,2,3,4,5,6), nrow = 3)
>R
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
>
> S <- matrix(c(1,2,3,4,5,6), nrow = 2)
>S
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
> R*S
Error in R * S : non-conformable arrays
> R <- matrix(c(1,2,3,4,5,6), 2,2)
>R
[,1] [,2]
[1,] 1 3
[2,] 2 4
> S <- matrix(c(1,2,3,4,5,6), nrow = 2,2)
>S
[,1] [,2]
[1,] 1 3
[2,] 2 4
> A=matrix(c(1,2,3,4,5,6,7,8,9),3,3)
>A
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> diag(A)
[1] 1 5 9
> diag(4)
[,1] [,2] [,3] [,4]
[1,] 1 0 0 0
[2,] 0 1 0 0
[3,] 0 0 1 0
[4,] 0 0 0 1
> B=diag(A)
> diag(B)
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 5 0
[3,] 0 0 9
> B=diag(A)
> diag(B)
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 5 0
[3,] 0 0 9
>

Commands

DATASET COMMANDS

8
CORRELATION
cor(cars$speed,cars$dist)

CORRELATION test
cor.test(cars$speed,cars$dist)

NEW dataset
data("EuStockMarkets")
print(EuStockMarkets)
summary(EuStockMarkets)
range(EuStockMarkets)
dim(EuStockMarkets)

data("AirPassengers")
print(AirPassengers)
summary(AirPassengers)

Vector
cia1 = c(20,10,15,19,23)
cia2 = c(22,20,27,17,21)
total=cia1+cia2
total

#numeric
x<- 10.5
class(x)

#integer
x<- 1000L
class(x)

x<- 1000L
typeof(x)

#complex
x<- 9i + 3
class(x)

# character/string
x <- "R is exciting"
class(x)

# logical/boolean
x <- TRUE
class(x)

#LIST
# List of strings
thislist <- list("apple", "banana", "cherry")

# Print the list


thislist

x = matrix(1:9, nrow = 3, ncol = 3)


x

x = matrix(1:9, nrow = 3, ncol = 3, byrow = TRUE)


x

X = array(1:24, dim = c(4, 3, 2))


X

X = array(1:24, dim = c(4, 6))


X

#DATAFRAMES
# Create a data frame
Data_Frame <- data.frame (
Training = c("Strength", "Stamina", "Other"),
Pulse = c(100, 150, 120),
Duration = c(60, 30, 45)
)

# Print the data frame


Data_Frame

#PLOT
plot(1,5)
b=c(10,10,20,20,20,20,20,20,20,30,50,50,50,50)
hist(b)

plot(1:5, type="l")

Resulls
> data("cars")
> print(cars)
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
7 10 18
8 10 26
9 10 34
10 11 17
11 11 28
12 12 14
13 12 20
14 12 24
15 12 28
16 13 26
17 13 34
18 13 34
19 13 46
20 14 26
21 14 36
22 14 60
23 14 80
24 15 20
25 15 26
26 15 54
27 16 32
28 16 40
29 17 32
30 17 40
31 17 50
32 18 42
33 18 56
34 18 76
35 18 84
36 19 36
37 19 46
38 19 68
39 20 32
40 20 48
41 20 52
42 20 56
43 20 64
44 22 66
45 23 54
46 24 70
47 24 92
48 24 93
49 24 120
50 25 85
> summary(cars)
speed dist
Min. : 4.0 Min. : 2.00
1st Qu.:12.0 1st Qu.: 26.00
Median :15.0 Median : 36.00
Mean :15.4 Mean : 42.98
3rd Qu.:19.0 3rd Qu.: 56.00
Max. :25.0 Max. :120.00
> head(cars)
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
> tail(cars)
speed dist
45 23 54
46 24 70
47 24 92
48 24 93
49 24 120
50 25 85
> head(cars,13)
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
7 10 18
8 10 26
9 10 34
10 11 17
11 11 28
12 12 14
13 12 20
> print(cars$speed)
[1] 4 4 7 7 8 9 10 10 10 11 11 12 12 12 12 13 13 13 13 14 14 14 14 15 15 15 16 16
17 17 17
[32] 18 18 18 18 19 19 19 20 20 20 20 20 22 23 24 24 24 24 25
> print(cars$dist)
[1] 2 10 4 22 16 10 18 26 34 17 28 14 20 24 28 26 34 34 46 26 36 60 80
[24] 20 26 54 32 40 32 40 50 42 56 76 84 36 46 68 32 48 52 56 64 66 54
70
[47] 92 93 120 85
> range(cars$speed)
[1] 4 25
> dim(cars)
[1] 50 2
> nrow(cars)
[1] 50
> ncol(cars)
[1] 2
> head(cars$speed,12)
[1] 4 4 7 7 8 9 10 10 10 11 11 12
> data("EuStockMarkets")
> print(EuStockMarkets)
Time Series:
Start = c(1991, 130)
End = c(1998, 169)
Frequency = 260
DAX SMI CAC FTSE
1991.496 1628.75 1678.1 1772.8 2443.6
1991.500 1613.63 1688.5 1750.5 2460.2
1991.504 1606.51 1678.6 1718.0 2448.2
1991.508 1621.04 1684.1 1708.1 2470.4
1991.512 1618.16 1686.6 1723.1 2484.7
1991.515 1610.61 1671.6 1714.3 2466.8
1991.519 1630.75 1682.9 1734.5 2487.9
1991.523 1640.17 1703.6 1757.4 2508.4
1991.527 1635.47 1697.5 1754.0 2510.5
1991.531 1645.89 1716.3 1754.3 2497.4
1991.535 1647.84 1723.8 1759.8 2532.5
1991.538 1638.35 1730.5 1755.5 2556.8
1991.542 1629.93 1727.4 1758.1 2561.0
1991.546 1621.49 1733.3 1757.5 2547.3
1991.550 1624.74 1734.0 1763.5 2541.5
1991.554 1627.63 1728.3 1762.8 2558.5
1991.558 1631.99 1737.1 1768.9 2587.9
1991.562 1621.18 1723.1 1778.1 2580.5
1991.565 1613.42 1723.6 1780.1 2579.6
1991.569 1604.95 1719.0 1767.7 2589.3
1991.573 1605.75 1721.2 1757.9 2595.0
1991.577 1616.67 1725.3 1756.6 2595.6
1991.581 1619.29 1727.2 1754.7 2588.8
1991.585 1620.49 1727.2 1766.8 2591.7
1991.588 1619.67 1731.6 1766.5 2601.7
1991.592 1623.07 1724.1 1762.2 2585.4
1991.596 1613.98 1716.9 1759.5 2573.3
1991.600 1631.87 1723.4 1782.4 2597.4
1991.604 1630.37 1723.0 1789.5 2600.6
1991.608 1633.47 1728.4 1783.5 2570.6
1991.612 1626.55 1722.1 1780.4 2569.4
1991.615 1650.43 1724.5 1808.8 2584.9
1991.619 1650.06 1733.6 1820.3 2608.8
1991.623 1654.11 1739.0 1820.3 2617.2
1991.627 1653.60 1726.2 1820.3 2621.0
1991.631 1501.82 1587.4 1687.5 2540.5
1991.635 1524.28 1630.6 1725.6 2554.5
1991.638 1603.65 1685.5 1792.9 2601.9
1991.642 1622.49 1701.3 1819.1 2623.0
1991.646 1636.68 1718.0 1833.5 2640.7
1991.650 1652.10 1726.2 1853.4 2640.7
1991.654 1645.81 1716.6 1849.7 2619.8
1991.658 1650.36 1725.8 1851.8 2624.2
1991.662 1651.55 1737.4 1857.7 2638.2
1991.665 1649.88 1736.6 1864.3 2645.7
1991.669 1653.52 1732.4 1863.5 2679.6
1991.673 1657.51 1731.2 1873.2 2669.0
1991.677 1649.55 1726.9 1860.8 2664.6
1991.681 1649.09 1727.8 1868.7 2663.3
1991.685 1646.41 1720.2 1860.4 2667.4
1991.688 1638.65 1715.4 1855.9 2653.2
1991.692 1625.80 1708.7 1840.5 2630.8
1991.696 1628.64 1713.0 1842.6 2626.6
1991.700 1632.22 1713.5 1861.2 2641.9
1991.704 1633.65 1718.0 1876.2 2625.8
1991.708 1631.17 1701.7 1878.3 2606.0
1991.712 1635.80 1701.7 1878.4 2594.4
1991.715 1621.27 1684.9 1869.4 2583.6
1991.719 1624.70 1687.2 1880.4 2588.7
1991.723 1616.13 1690.6 1885.5 2600.3
1991.727 1618.12 1684.3 1888.4 2579.5
1991.731 1627.80 1679.9 1885.2 2576.6
1991.735 1625.79 1672.9 1877.9 2597.8
1991.738 1614.80 1663.1 1876.5 2595.6
1991.742 1612.80 1669.3 1883.8 2599.0
1991.746 1605.47 1664.7 1880.6 2621.7
1991.750 1609.32 1672.3 1887.4 2645.6
1991.754 1607.48 1687.7 1878.3 2644.2
1991.758 1607.48 1686.8 1867.1 2625.6
1991.762 1604.89 1686.6 1851.9 2624.6
1991.765 1589.12 1675.8 1843.6 2596.2
1991.769 1582.27 1677.4 1848.1 2599.5
1991.773 1567.99 1673.2 1843.4 2584.1
1991.777 1568.16 1665.0 1843.6 2570.8
1991.781 1569.71 1671.3 1833.8 2555.0
1991.785 1571.74 1672.4 1833.4 2574.5
1991.788 1585.41 1676.2 1856.9 2576.7
1991.792 1570.01 1692.6 1863.4 2579.0
1991.796 1561.89 1696.5 1855.5 2588.7
1991.800 1565.18 1716.1 1864.2 2601.1
1991.804 1570.34 1713.3 1846.0 2575.7
1991.808 1577.00 1705.1 1836.8 2559.5
1991.812 1590.29 1711.3 1830.4 2561.1
1991.815 1572.72 1709.8 1831.6 2528.3
1991.819 1572.07 1688.6 1834.8 2514.7
1991.823 1579.19 1698.9 1852.1 2558.5
1991.827 1588.73 1700.0 1849.8 2553.3
1991.831 1586.01 1693.0 1861.8 2577.1
1991.835 1579.77 1683.9 1856.7 2566.0
1991.838 1572.58 1679.2 1856.7 2549.5
1991.842 1568.09 1673.9 1841.5 2527.8
1991.846 1578.21 1683.9 1846.9 2540.9
1991.850 1573.94 1688.4 1836.1 2534.2
1991.854 1582.06 1693.9 1838.6 2538.0
1991.858 1610.18 1720.9 1857.6 2559.0
1991.862 1605.16 1717.9 1857.6 2554.9
1991.865 1623.84 1733.6 1858.4 2575.5
1991.869 1615.26 1729.7 1846.8 2546.5
1991.873 1627.08 1735.6 1868.5 2561.6
1991.877 1626.97 1734.1 1863.2 2546.6
1991.881 1605.70 1699.3 1808.3 2502.9
1991.885 1589.70 1678.6 1765.1 2463.1
1991.888 1589.70 1675.5 1763.5 2472.6
1991.892 1603.26 1670.1 1766.0 2463.5
1991.896 1599.75 1652.2 1741.3 2446.3
1991.900 1590.86 1635.0 1743.3 2456.2
1991.904 1603.50 1654.9 1769.0 2471.5
1991.908 1589.86 1642.0 1757.9 2447.5
1991.912 1587.92 1638.7 1754.9 2428.6
1991.915 1571.06 1622.6 1739.7 2420.2
1991.919 1549.81 1596.1 1708.8 2414.9
1991.923 1549.36 1612.4 1722.2 2420.2
1991.927 1554.65 1625.0 1713.9 2423.8
1991.931 1557.52 1610.5 1703.2 2407.0
1991.935 1555.31 1606.6 1685.7 2388.7
1991.938 1559.76 1610.7 1663.4 2409.6
1991.942 1548.44 1603.1 1636.9 2392.0
1991.946 1543.99 1591.5 1645.6 2380.2
1991.950 1550.21 1605.2 1671.6 2423.3
1991.954 1557.03 1621.4 1688.3 2451.6
1991.958 1551.78 1622.5 1696.8 2440.8
1991.962 1562.89 1626.6 1711.7 2432.9
1991.965 1570.28 1627.4 1706.2 2413.6
1991.969 1559.26 1614.9 1684.2 2391.6
1991.973 1545.87 1602.3 1648.5 2358.1
1991.977 1542.77 1598.3 1633.6 2345.4
1991.981 1542.77 1627.0 1699.1 2384.4
1991.985 1542.77 1627.0 1699.1 2384.4
1991.988 1542.77 1627.0 1722.5 2384.4
1991.992 1564.27 1655.7 1720.7 2418.7
1991.996 1577.26 1670.1 1741.9 2420.0
1992.000 1577.26 1670.1 1765.7 2493.1
1992.004 1577.26 1670.1 1765.7 2493.1
1992.008 1598.19 1670.1 1749.9 2492.8
1992.012 1604.05 1704.0 1770.3 2504.1
1992.015 1604.69 1711.8 1787.6 2493.2
1992.019 1593.65 1700.5 1778.7 2482.9
1992.023 1581.68 1690.3 1785.6 2467.1
1992.027 1599.14 1715.4 1833.9 2497.9
1992.031 1613.82 1723.5 1837.4 2477.9
1992.035 1620.45 1719.4 1824.3 2490.1
1992.038 1629.51 1734.4 1843.8 2516.3
1992.042 1663.70 1772.8 1873.6 2537.1
1992.046 1664.09 1760.3 1860.2 2541.6
1992.050 1669.29 1747.2 1860.2 2536.7
1992.054 1685.14 1750.2 1865.9 2544.9
1992.058 1687.07 1755.3 1867.9 2543.4
1992.062 1680.13 1754.6 1841.3 2522.0
1992.065 1671.84 1751.2 1838.7 2525.3
1992.069 1669.52 1752.5 1849.9 2510.4
1992.073 1686.71 1769.4 1869.3 2539.9
1992.077 1685.51 1767.6 1890.6 2552.0
1992.081 1671.01 1750.0 1879.6 2546.5
1992.085 1683.06 1747.1 1873.9 2550.8
1992.088 1685.70 1753.5 1875.3 2571.2
1992.092 1685.66 1752.8 1857.0 2560.2
1992.096 1678.77 1752.9 1856.5 2556.8
1992.100 1685.85 1764.7 1865.8 2547.1
1992.104 1683.71 1776.8 1860.6 2534.3
1992.108 1686.59 1779.3 1861.6 2517.2
1992.112 1683.73 1785.1 1865.6 2538.4
1992.115 1679.14 1798.2 1864.1 2537.1
1992.119 1685.03 1794.1 1861.6 2523.7
1992.123 1680.81 1795.2 1876.5 2522.6
1992.127 1676.17 1780.4 1865.1 2513.9
1992.131 1688.46 1789.5 1882.1 2541.0
1992.135 1696.55 1794.2 1912.2 2555.9
1992.138 1690.24 1784.4 1915.4 2536.7
1992.142 1711.35 1800.1 1951.2 2543.4
1992.146 1711.29 1804.0 1962.4 2542.3
1992.150 1729.86 1816.2 1976.5 2559.7
1992.154 1716.63 1810.5 1953.5 2546.8
1992.158 1743.36 1821.9 1981.3 2565.0
1992.162 1745.17 1828.2 1985.1 2562.0
1992.165 1746.76 1840.6 1983.4 2562.1
1992.169 1749.29 1841.1 1979.7 2554.3
1992.173 1763.86 1846.3 1983.8 2565.4
1992.177 1762.27 1850.0 1988.1 2558.4
1992.181 1762.29 1839.0 1973.0 2538.3
1992.185 1746.77 1820.2 1966.9 2533.1
1992.188 1753.50 1815.2 1976.3 2550.7
1992.192 1753.21 1820.6 1993.9 2574.8
1992.196 1739.88 1807.1 1968.0 2522.4
1992.200 1723.92 1791.4 1941.8 2493.3
1992.204 1734.42 1806.2 1947.1 2476.0
1992.208 1723.13 1798.7 1929.2 2470.7
1992.212 1732.92 1818.2 1943.6 2491.2
1992.215 1729.89 1820.5 1928.2 2464.7
1992.219 1725.74 1833.3 1922.0 2467.6
1992.223 1730.90 1837.1 1919.1 2456.6
1992.227 1714.17 1818.2 1884.6 2441.0
1992.231 1716.20 1824.1 1896.3 2458.7
1992.235 1719.06 1830.1 1928.3 2464.9
1992.238 1718.21 1835.6 1934.8 2472.2
1992.242 1698.84 1828.7 1923.5 2447.9
1992.246 1714.76 1839.2 1943.8 2452.9
1992.250 1718.35 1837.2 1942.4 2440.1
1992.254 1706.69 1826.7 1928.1 2408.6
1992.258 1723.37 1838.0 1942.0 2405.4
1992.262 1716.18 1829.1 1942.7 2382.7
1992.265 1738.78 1843.1 1974.8 2400.9
1992.269 1737.41 1850.5 1975.4 2404.2
1992.273 1714.77 1827.1 1907.5 2393.2
1992.277 1724.24 1829.1 1943.6 2436.4
1992.281 1733.77 1848.0 1974.1 2572.6
1992.285 1729.96 1840.5 1963.3 2591.0
1992.288 1734.46 1853.8 1972.3 2600.5
1992.292 1744.35 1874.1 1990.7 2640.2
1992.296 1746.88 1871.3 1978.2 2638.6
1992.300 1746.88 1871.3 1978.2 2638.6
1992.304 1746.88 1871.3 1978.2 2638.6
1992.308 1747.47 1860.5 1980.4 2625.8
1992.312 1753.10 1874.7 1983.7 2607.8
1992.315 1745.17 1880.1 1978.1 2609.8
1992.319 1745.72 1874.7 1984.9 2643.0
1992.323 1742.92 1875.6 1995.7 2658.2
1992.327 1731.68 1859.5 2006.6 2651.0
1992.331 1731.18 1874.2 2036.7 2664.9
1992.335 1728.09 1880.1 2031.1 2654.1
1992.338 1728.09 1880.1 2031.1 2659.8
1992.342 1731.29 1907.7 2041.6 2659.8
1992.346 1733.82 1920.5 2046.9 2662.2
1992.350 1745.78 1937.3 2047.2 2698.7
1992.354 1752.57 1936.8 2063.4 2701.9
1992.358 1748.13 1949.1 2063.4 2725.7
1992.362 1750.70 1963.7 2077.5 2737.8
1992.365 1747.91 1950.8 2063.6 2722.4
1992.369 1745.79 1953.5 2053.2 2720.5
1992.373 1735.34 1945.0 2017.0 2694.7
1992.377 1719.92 1921.1 2024.0 2682.6
1992.381 1763.59 1939.1 2051.6 2703.6
1992.385 1766.76 1928.0 2023.1 2700.6
1992.388 1785.40 1933.4 2030.8 2711.9
1992.392 1783.56 1925.7 2016.8 2702.0
1992.396 1804.42 1931.7 2045.1 2715.0
1992.400 1812.33 1928.7 2046.3 2715.0
1992.404 1799.51 1924.5 2029.6 2704.6
1992.408 1792.80 1914.2 2014.1 2698.6
1992.412 1792.80 1914.2 2014.1 2694.2
1992.415 1806.36 1920.6 2033.3 2707.6
1992.419 1798.23 1923.3 2017.4 2697.6
1992.423 1800.62 1930.4 2024.9 2705.9
1992.427 1786.19 1915.2 1992.6 2680.9
1992.431 1791.35 1916.9 1994.9 2681.9
1992.435 1789.05 1913.8 1981.6 2668.5
1992.438 1789.05 1913.8 1981.6 2645.8
1992.442 1784.71 1899.7 1962.2 2635.4
1992.446 1789.45 1888.0 1953.7 2636.1
1992.450 1779.74 1868.8 1928.8 2614.1
1992.454 1786.97 1879.9 1928.3 2603.7
[ reached getOption("max.print") -- omitted 1610 rows ]
> summary(EuStockMarkets)
DAX SMI CAC FTSE
Min. :1402 Min. :1587 Min. :1611 Min. :2281
1st Qu.:1744 1st Qu.:2166 1st Qu.:1875 1st Qu.:2843
Median :2141 Median :2796 Median :1992 Median :3247
Mean :2531 Mean :3376 Mean :2228 Mean :3566
3rd Qu.:2722 3rd Qu.:3812 3rd Qu.:2274 3rd Qu.:3994
Max. :6186 Max. :8412 Max. :4388 Max. :6179
> range(EuStockMarkets)
[1] 1402.34 8412.00
> range(EuStockMarkets$DAX)
Error in EuStockMarkets$DAX : $ operator is invalid for atomic vectors
> dim(EuStockMarkets)
[1] 1860 4
> data("AirPassengers")
> print(AirPassengers)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1949 112 118 132 129 121 135 148 148 136 119 104 118
1950 115 126 141 135 125 149 170 170 158 133 114 140
1951 145 150 178 163 172 178 199 199 184 162 146 166
1952 171 180 193 181 183 218 230 242 209 191 172 194
1953 196 196 236 235 229 243 264 272 237 211 180 201
1954 204 188 235 227 234 264 302 293 259 229 203 229
1955 242 233 267 269 270 315 364 347 312 274 237 278
1956 284 277 317 313 318 374 413 405 355 306 271 306
1957 315 301 356 348 355 422 465 467 404 347 305 336
1958 340 318 362 348 363 435 491 505 404 359 310 337
1959 360 342 406 396 420 472 548 559 463 407 362 405
1960 417 391 419 461 472 535 622 606 508 461 390 432
> summary(AirPassengers)
Min. 1st Qu. Median Mean 3rd Qu. Max.
104.0 180.0 265.5 280.3 360.5 622.0
> cor(cars$speed,cars$dist)
[1] 0.8068949
> cor.test(cars$speed,cars$dist)

Pearson's product-moment correlation

data: cars$speed and cars$dist


t = 9.464, df = 48, p-value = 1.49e-12
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.6816422 0.8862036
sample estimates:
cor
0.8068949

> cia1 = c(20,10,15,19,23)


> cia2 = (22,20,27,17,21)
Error: unexpected ',' in "cia2 = (22,"
> total = cia1 + cia2
Error: object 'cia2' not found
> cia1 = c(20,10,15,19,23)
> cia2 = c(22,20,27,17,21)
> total = cia1 + cia2
> total=cia1+cia2
> total=cia1+cia2
> total
[1] 42 30 42 36 44
> x<- 10.5
> class(x)
[1] "numeric"
> x<- 1000L
> class(x)
[1] "integer"
> x<- 1000L
> typeof(x)
[1] "integer"
> x<- 9i + 3
> class(x)
[1] "complex"
> x <- "R is exciting"
> class(x)
[1] "character"
> x <- TRUE
> class(x)
[1] "logical"
> # List of strings
> thislist <- list("apple", "banana", "cherry")
>
> # Print the list
> thislist
[[1]]
[1] "apple"

[[2]]
[1] "banana"

[[3]]
[1] "cherry"

> x = matrix(1:9, nrow = 3, ncol = 3)


>x
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> x = matrix(1:9, nrow = 3, ncol = 3, byrow = TRUE)
>x
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
> X = array(1:24, dim = c(4, 3, 2))
>X
,,1

[,1] [,2] [,3]


[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12

,,2
[,1] [,2] [,3]
[1,] 13 17 21
[2,] 14 18 22
[3,] 15 19 23
[4,] 16 20 24

> X = array(1:24, dim = c(4, 3))


>X
[,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12
> X = array(1:24, dim = c(4, 6))
>X
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 5 9 13 17 21
[2,] 2 6 10 14 18 22
[3,] 3 7 11 15 19 23
[4,] 4 8 12 16 20 24
> Data_Frame <- data.frame (
+ Training = c("Strength", "Stamina", "Other"),
+ Pulse = c(100, 150, 120),
+ Duration = c(60, 30, 45)
+)
>
> # Print the data frame
> Data_Frame
Training Pulse Duration
1 Strength 100 60
2 Stamina 150 30
3 Other 120 45
> plot(1,5)
> b=c(10,10,20,20,20,20,20,20,20,30,50,50,50,50)
> hist(b)
> plot(1:5, type="l")

Commands
x = c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
y = c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
cor(x,y)
cor.test(x,y)

r=lm(y~x)
print(r)
print(summary(r))
t=data.frame(x=170)
w=predict(r,t)
print(w)

Null hypothesis of regression


There is no significant impact of height of individuals (independent variable) on weight
of the individuals (dependent individuals)

Alternative hypothesis
There is a significant impact of height of individuals (independent variable) on weight of
respective individuals (dependent individuals)

regression equations:
y = a + bx
wt = a + b(Ht)
wt = -38.45 + 0.67461 (ht)

if the probability value less than 0.05, reject the null hypothesis
Dimensions:
direct = +ve
Magnitiude = 0.674
Significance = yes

if probability is more than 0.05 than there is no significant relationship, thus no further
dimensions are considered

Interpretation:
since the probability value of x () is less than 0.05, it is significant.
there is a positive impact of height of individuals(x) on weight of individuals(y).
further it clearly indicates that 1cm increase in height of individuals leads to increase in
0.674 kg of weight of the respective individuals
#how to apply regression from external files
M=read.csv(""
M
summary(M)
r=lm(NiftyIT~(NIKKIE+FTSE+GBP+Crudeoil), data=M)
print(r)
print(summary(r))
t=data.frame(NIKKIE=100,FTSE=30,GBP=0.5,crudeoil=1.2)
w=predict(r,t)
print(w)

Null hypothesis
there is no significant impact of NIKKIE, FTSE, GBP and crudeoil on NiftyIT prices

DV = NiftyIT
IV = NIKKIE, FTSE, GBP and crudeoil

this is multiple regression analysis as more than 1 independent variables are present

Equation:
NiftyIT = B0 + B1(NIKKIE), B2(FTSE), + B3(GBP) + B4(Crudeoil)

Interpretation:
NIKKIE (+ve impact, 1 unit increase in NIKKIE prices causes increase of 0.11 units in
NiftyIT prices)
FTSE (+ve impact, 1 unit increase in FTSE prices causes increase of 0.36 units in
NiftyIt prices)
GBP
the probability value of GBP is less than 0.05, it means it is significant so it clearly
indicates that there is a negative impact of GBP prices on NiftyIT prices . Further, 1 unit
increase in GBP prices, causes decrease of 32.875 units of NiftyIT prices. Similarly, 1
unitb decrease in GBP prices causes increase of 32.875 units of NiftyIT prices.
Crudeoil (since the probability value of crudeoil is more than 0.05, it means that it is
insignificant)

Result
> x = c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
> y = c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
> cor(x,y)
[1] 0.9771296
> cor.test(x,y)
Pearson's product-moment correlation

data: x and y
t = 12.997, df = 8, p-value = 1.164e-06
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.9031373 0.9947558
sample estimates:
cor
0.9771296

> r=lm(y-x)
Error in formula.default(object, env = baseenv()) : invalid formula
> r=lm(y-x)
Error in formula.default(object, env = baseenv()) : invalid formula
> print(r)
Error in print(r) : object 'r' not found
> r=lm(y~x)
> print(r)

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept) x
-38.4551 0.6746

> r=lm(y~x)
> print(r)

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept) x
-38.4551 0.6746

> print(summary(r))

Call:
lm(formula = y ~ x)

Residuals:
Min 1Q Median 3Q Max
-6.3002 -1.6629 0.0412 1.8944 3.9775

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -38.45509 8.04901 -4.778 0.00139 **
x 0.67461 0.05191 12.997 1.16e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.253 on 8 degrees of freedom


Multiple R-squared: 0.9548, Adjusted R-squared: 0.9491
F-statistic: 168.9 on 1 and 8 DF, p-value: 1.164e-06

> t=data.frame(x=170)
> w=predict(r,t)
> print(w)
1
76.22869
> M=read.csv("downloads:\\FD8.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'downloads:\FD8.csv': No such file or directory
> summary(M)
V1 V2 V3
Min. :1.0 Min. :2.0 Min. :3.0
1st Qu.:1.0 1st Qu.:2.0 1st Qu.:3.0
Median :1.0 Median :2.0 Median :3.0
Mean :2.0 Mean :3.0 Mean :4.0
3rd Qu.:2.5 3rd Qu.:3.5 3rd Qu.:4.5
Max. :4.0 Max. :5.0 Max. :6.0
> r=lm(NiftyIT~(NIKKIE+FTSE+GBP+Crudeoil), data=M)
Error in model.frame.default(formula = NiftyIT ~ (NIKKIE + FTSE + GBP + :
'data' must be a data.frame, not a matrix or an array
> print(r)

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept) x
-38.4551 0.6746
> print(summary(r))

Call:
lm(formula = y ~ x)

Residuals:
Min 1Q Median 3Q Max
-6.3002 -1.6629 0.0412 1.8944 3.9775

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -38.45509 8.04901 -4.778 0.00139 **
x 0.67461 0.05191 12.997 1.16e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.253 on 8 degrees of freedom


Multiple R-squared: 0.9548, Adjusted R-squared: 0.9491
F-statistic: 168.9 on 1 and 8 DF, p-value: 1.164e-06

> t=data.frame(NIKKIE=100,FTSE=30,GBP=0.5,crudeoil=1.2)
> w=predict(r,t)
Warning message:
'newdata' had 1 row but variables found have 10 rows
> print(w)
1 2 3 4 5 6 7 8 9 10
63.41109 78.92713 54.64115 87.02246 47.89505 53.29193 82.30018 71.50642 64.08570
49.91888
> M=read.csv("downloads:\\FD8.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'downloads:\FD8.csv': No such file or directory
>M
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 1 2 3
> M=read.csv("Macintosh HD/Users/priyanshisinghi/Downloads:\\FD8.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'Macintosh HD/Users/priyanshisinghi/Downloads:\FD8.csv': No such
file or directory
>M
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 1 2 3
> M=read.csv("Home/Downloads:\\FD8.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'Home/Downloads:\FD8.csv': No such file or directory
>M
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 1 2 3
> M=read.csv("Home/Downloads/FD8.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'Home/Downloads/FD8.csv': No such file or directory
>M
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 1 2 3
> M=read.csv("https://doc-04-b8-docs.googleusercontent.com/docs/securesc/
6u9i13ans5a0o3iq1i05o6eubfei2jcp/688eqndian099bh9u76a4ips1vpr8tbr/
1680151500000/01025451512579028975/07148191268268416602/1H-
9w3JxryeFA1xC9PCLbnDFAI7k5PK60?
e=download&ax=ALy03A7k5W9zso8_Ed15p1fyTzrHkQlOcghHw8WDTLHIcC5Z4rW
xsj5x3K7vCxLgZXewFL85uxhsSvSu6ZYllK6c_nZQcG-5yg1GAGLbAfo--
4Ea7N_SdUrySh0b0-
Z6vIS550jYcNon9gOljejLGQNuoU29lKVQuW7gsx6e5L8w4P5MFmtXFU8j0dSZ7kh7
vZOrktcv_93-N-
Ed3JOy1DhQq4zwhF7kVBEMZVNjmwF1exHPRZSyn_rXKnYxBDtn9aPnGIGX9aeg9
dt39laIOkur4dGoLzoF77LvMSAyAMjhKXRhZgG1VQ6ToZTqCJTQ-
g1FXJ2C5NdUTaEaUSGz_r1LkVjZ5c8lPLhNFUaIPM0KAKFIt4v3uVnLySMClKZAvI
jNgzMQkjuWM6Vtw6bnjuvZB2I9argyrgXoC12ix061Ij9LlW8uLwB9hWsQM1FxEINf
SbI6BIF7amH1COPnaHhELMhIJVgbjPG4d7IS17KjqN68ExJx9omx1eNJSByI8dOKUs
FP2iK2Uu7qsdX-NPkkI4eEBZeteDOsVi7f-
MFc9zOT4rUBtBdn4iQLV6B2W58q1BKoRdjRiqPmxJcyYIpsHEvoJDzP6nR7U-
zjZsylBbYcBucbbFrcZ2skJfWlfK04UdhxOQlSNRtWP7CJVmLUC7scnsbaB-
LXNqYNWpGtXpwEGYTOTnUYKUTwlO6B4IU0h4O7Wu35wnCQ1WhmBenLKc3m
8LsMGoD3hFuSnBFO5ZXi6lRiOhXYSWMayj5XwAE7UrJlIkNcZlwtId4QJDDQCCY
8bSR4hZ933Pg7AkbFPBjsa0gLEd6lbt7STPiBdis7e1lVaGt9MR4GCruxwRJ2GeJ4htzetl
peqSV5U0dz9rjx0nQRiGhL-PwBrgUw0gh8Yj-QYmI1nk9ExqfqonpO520m6JdK8K-
pyyFZjsdf-K4mP6GahG42inpOUMVtC1biMPBmB8tuHA&uuid=54f18972-0a75-4d1c-
82ad-5ebde1964ca5&authuser=0")
Error in file(file, "rt") : cannot open connection
In addition: Warning message:
In file(file, "rt") :
URL
'https://doc-04-b8-docs.googleusercontent.com/docs/securesc/6u9i13ans5a0o3iq1i05o6eu
bfei2jcp/688eqndian099bh9u76a4ips1vpr8tbr/
1680151500000/01025451512579028975/07148191268268416602/1H-
9w3JxryeFA1xC9PCLbnDFAI7k5PK60?
e=download&ax=ALy03A7k5W9zso8_Ed15p1fyTzrHkQlOcghHw8WDTLHIcC5Z4rW
xsj5x3K7vCxLgZXewFL85uxhsSvSu6ZYllK6c_nZQcG-5yg1GAGLbAfo--
4Ea7N_SdUrySh0b0-
Z6vIS550jYcNon9gOljejLGQNuoU29lKVQuW7gsx6e5L8w4P5MFmtXFU8j0dSZ7kh7
vZOrktcv_93-N-
Ed3JOy1DhQq4zwhF7kVBEMZVNjmwF1exHPRZSyn_rXKnYxBDtn9aPnGIGX9aeg9
dt39laIOkur4dGoLzoF77LvMSAyAMjhKXRhZgG1VQ6ToZTqCJTQ-
g1FXJ2C5NdUTaEaUSGz_r1LkVjZ5c8lPLhNFUaIPM0KAKFIt4v3uVnLySMClKZAvI
jNgzMQkjuWM6Vtw6bnjuvZB2I9argyrgXoC12ix061Ij9LlW8uLwB9hWsQM1FxEINf
SbI6BIF7amH1COPnaHhELMhIJVgbjPG4d7IS17KjqN68ExJx9omx1eNJSByI8dOKUs
FP2iK2Uu7qsdX-NPkkI4eEBZeteDOsVi7f-
MFc9zOT4rUBtBdn4iQLV6B2W58q1BKoRdjRiqPmxJcyYIpsHEvoJDzP6nR7U-
zjZsylBbYcBucbbFrcZ2skJfWlfK04UdhxOQlSNRtWP7CJVmLUC7scnsbaB-
LXNqYNWpGtXpwEGYTOTnUYKUTwlO6B4IU0h4O7Wu35wnCQ1WhmBenLKc3m
8LsMGoD3hFuSnBFO5ZXi6lRiOhXYSWMayj [... truncated]
>M
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 1 2 3
> M=read.csv("FD8.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file 'FD8.csv': No such file or directory
>M
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 1 2 3
> summary(M)
V1 V2 V3
Min. :1.0 Min. :2.0 Min. :3.0
1st Qu.:1.0 1st Qu.:2.0 1st Qu.:3.0
Median :1.0 Median :2.0 Median :3.0
Mean :2.0 Mean :3.0 Mean :4.0
3rd Qu.:2.5 3rd Qu.:3.5 3rd Qu.:4.5
Max. :4.0 Max. :5.0 Max. :6.0
>

Commands

a=read.csv(file.choose())
a
print(a)
print(nrow(a))
summary(a)

z=readxl::read_excel(file.choose())
z=readxl::read_xlsx(file.choose())

RESULTS
a=read.csv(file.choose())
> a=read.csv(file.choose())
>a
Reg.No. Name S1 S2 S3 S4 S5
1 2120901 A 87 78 90 79 77
2 2120902 B 89 87 78 90 87
3 2120903 C 96 94 93 98 92
4 2120904 D 80 79 86 76 84
5 2120905 E 94 80 77 79 88
> print(a)
Reg.No. Name S1 S2 S3 S4 S5
1 2120901 A 87 78 90 79 77
2 2120902 B 89 87 78 90 87
3 2120903 C 96 94 93 98 92
4 2120904 D 80 79 86 76 84
5 2120905 E 94 80 77 79 88
> print(nrow(a))
[1] 5
> summary(a)
Reg.No. Name S1 S2 S3 S4
Min. :2120901 A:1 Min. :80.0 Min. :78.0 Min. :77.0 Min. :76.0
1st Qu.:2120902 B:1 1st Qu.:87.0 1st Qu.:79.0 1st Qu.:78.0 1st Qu.:79.0
Median :2120903 C:1 Median :89.0 Median :80.0 Median :86.0 Median :79.0
Mean :2120903 D:1 Mean :89.2 Mean :83.6 Mean :84.8 Mean :84.4
3rd Qu.:2120904 E:1 3rd Qu.:94.0 3rd Qu.:87.0 3rd Qu.:90.0 3rd Qu.:90.0
Max. :2120905 Max. :96.0 Max. :94.0 Max. :93.0 Max. :98.0
S5
Min. :77.0
1st Qu.:84.0
Median :87.0
Mean :85.6
3rd Qu.:88.0
Max. :92.0

Commands
libary(ggplot)

library(readxl)
PE3 <- read.csv("Downloads/PE3.csv")
View(PE3)
ggplot(PE3)

#piechart with percentages


slices <- c(10, 12, 4, 16, 8)
lbls <- c("US" , "UK" , "Australia" , "Germany" , "France")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct) # add percents to labels
lbls <- paste(lbls, "%", sep="") # add percents to labels
pie(slices, labels = lbls, col=rainbow(length(lbls)),
main="Pie Chart of countries")

barplot(salary,
main = "salary",
xlab = "Rs",
ylab = "Employee",
names.arg = c("ravi","shashi","ria","suma","roy","kiran"),
col = "darkred",
horiz = "TRUE")
empname=c("ravi","shashi","ria","suma","roy","kiran")
salary=c(2300,1250,3500,4200,5100,2250)
df=data.frame(empname,salary)
print(df)

library(readxl)
FD2 <- read_csv("Downloads/FD2.csv")
View(FD2)
summary(FD2)
head(FD2)
tail(FD2)
head(FD2,2)
tail(FD2,4)

FD2[c(2,3),]
FD2

N=FD2[c(1:10),]
N

O=FD2[c(21:30),]
O

r=lm(NASDAQD~(NiftymicapD+FTSED+NIKKIED+CrudeoilD),data=N)
print(r)
print(summary(r))

t=data.frame(NiftymicapD=5000,FTSED=7000, NIKKIED=7000, CrudeoilD=170)


w=predict(r,t)
print(w)

P=FD2[c(1:50),]
P
Q=FD2[c(150:200),]
Q
DF <- rbind(N,O)
DF

r=lm(NASDAQD~(NiftymicapD+FTSED+NIKKIED+CrudeoilD),data=DF)
print(r)
print(summary(r))

t=data.frame(NiftymicapD=5000,FTSED=7000, NIKKIED=7000, CrudeoilD=170)


w=predict(r,t)
print(w)

You might also like