0% found this document useful (0 votes)
131 views3 pages

R Programming Assignment

The document provides an example of creating a data frame in R using the rep and each functions. It assigns numbers 1 through 20 to the Plot variable and assigns different treatment categories to the Treatment variable using rep and c. It then uses data.frame to create a data frame called data from the Plot and Treatment variables.

Uploaded by

M sobrul Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views3 pages

R Programming Assignment

The document provides an example of creating a data frame in R using the rep and each functions. It assigns numbers 1 through 20 to the Plot variable and assigns different treatment categories to the Treatment variable using rep and c. It then uses data.frame to create a data frame called data from the Plot and Treatment variables.

Uploaded by

M sobrul Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Jagannath University

Assignment
On

Computer Programming with R


Course code: STA 3106

Submitted By Submitted To
SOBURUL ISLAM Dr. Md. Siddiqur Rahman
B200304003 Professor
Department of Statistics Department of Statistics
Jagannath University, Dhaka Jagannath University, Dhaka

Submitted Date : 26-03-2024


Problem: Make a data frame using ‘rep’ and ‘each’ functions like-
Plot Treatment
1 1 D
2 2 B
3 3 C
4 4 D
5 5 C
6 6 E
7 7 B
8 8 A
9 9 A
10 10 B
11 11 D
12 12 C
13 13 C
14 14 E
15 15 D
16 16 B
17 17 E
18 18 A
19 19 E
20 20 A
Solve:
> Plot<-1:20
> Treatment<-
+ c('D','B','C','D','C','E','B',rep('A',each=2),'B','D',rep('C',each=2),'E',
+ 'D','B',rep(c('E','A'),2))
> data<-data.frame(Plot,Treatment)

Explanation:
First of all, we assign the number 1 to 20 into a variable ‘Plot’.
Plot<-1:20
Second we assign the treatment category ‘A’, ‘B’,… into another variable
‘Treatment’.
Treatment<-
c('D','B','C','D','C','E','B',rep('A',each=2),'B','D',rep('C',each=2),'E',
'D','B',rep(c('E','A'),2))
Finally we make a data frame using function ‘data.frame’ and suppose the
data frame name is ‘data’.
data<-data.frame(Plot,Treatment)
Then we call data to get the data frame.
>data
Plot Treatment
1 1 D
2 2 B
3 3 C
4 4 D
5 5 C
6 6 E
7 7 B
8 8 A
9 9 A
10 10 B
11 11 D
12 12 C
13 13 C
14 14 E
15 15 D
16 16 B
17 17 E
18 18 A
19 19 E
20 20 A

You might also like