0% found this document useful (0 votes)
22 views

File Handling

The document demonstrates various data handling operations in R including reading in a dataset, writing the dataset to a CSV file, performing scatter plots, bar plots, histograms and other visualizations on the dataset. It also shows operations for subsetting the data, finding minimum and maximum values, and retrieving dimension and column names of the dataset.

Uploaded by

Sandij
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

File Handling

The document demonstrates various data handling operations in R including reading in a dataset, writing the dataset to a CSV file, performing scatter plots, bar plots, histograms and other visualizations on the dataset. It also shows operations for subsetting the data, finding minimum and maximum values, and retrieving dimension and column names of the dataset.

Uploaded by

Sandij
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

FILE HANDLING

Data sets
data("cars")

cars

OUTPUT:

> 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
Write operation:
write.table(cars, file = "car.csv", sep = ",", row.names = FALSE, col.names = TRUE)

OUTPUT:

> write.table(cars, file = "car.csv", sep = ",", row.names = FALSE,


col.names = TRUE)

READ OPERATION:
read.csv("C:\\Users\\user\\Documents\\car.csv")

OUTPUT:

> read.csv("C:\\Users\\user\\Documents\\car.csv")

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

PLOT:
Types
1.scatter plot:
plot(cars$speed,cars$dist)

OUTPUT:
> plot(cars$speed,cars$dist)
2.BARPLOT:
barplot(cars$speed,cars$dist)

OUTPUT:
> barplot(cars$speed,cars$dist)
Barplot with color:
barplot(cars$speed,cars$dist,col = "red")

OUTPUT:
>barplot(cars$speed.cars$dist,col= “red”)

Barplot with axis name:


barplot(cars$speed,cars$dist, xlab = "distance",ylab = "speed")
OUTPUT:

>barplot(cars$speed,cars$dist, xlab = "distance",ylab = "speed")

3.stripchart:
stripchart(cars$dist)

OUTPUT:

>stripchart(cars$dist)
4.Box plot
boxplot(cars$dist)

OUTPUT:

>boxplot(cars$dist)
5.HISTOGRAM
hist(cars$dist,main="distance",xlab="dist")

OUTPUT:

>hist(cars$dist,main="distance",xlab="dist")

6.Q-Q plot
qqnorm(cars$dist)

qqline(cars$dist)

OUTPUT:
SUBSET:
retval<-subset(cars,dist>60)

Retval

OUTPUT:
> retval

speed dist
23 14 80
34 18 76
35 18 84
38 19 68
43 20 64
44 22 66
46 24 70
47 24 92
48 24 93
49 24 120
50 25 85

BARPLOT OF SUBSET:
barplot(retval$speed,retval$dist,col="blue")

OUTPUT:

MIN AND MAX VALUE OF DATASET:

miin<-min(cars$dist)
miin

maxi<-max(cars$dist)

maxi

OUTPUT:
> miin

[1] 2

> maxi<-max(cars$dist)
> maxi

[1] 120

DIMENSION OF DATASET:
dim(cars)
OUTPUT:
> dim(cars)
[1] 50 2

RETRIVING COL NAMES:


names(cars)
OUTPUT:
> names(cars)
[1] "speed" "dist"

RETRIVING FISRT AND LAST SIX ATTRIBUTES:


head(cars)

tail(cars)

OUPUT:
> 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

You might also like