Category Archives for "R Programming"

Jan 13

R append example

By ganpati | R Programming

14append_img

append function in R

What it does?
It inserts values from a vector to a given vector after a certain specified length
Syntax:
append (vector1, vector2, length=n)
Example:
x<- c(1,3,5,7,9) append (x, c(8,9,10), after=4) [1] 1 3 5 7 8 9 10 9

Jan 13

R rbind example

By ganpati | R Programming

12rbind_img

rbind

What it does?
It adds the rows of the second data frame to the first data frame provided both data frames have same number of columns
Syntax:
print (data frame1, data frame2)
Example:
We have two dataframes samp1 and samp2 as below:
> samp1

col1 col2 col3

1 1 6 11
2 2 7 12
3 3 8 13
4 4 9 14
5 5 10 15
> samp2

col1 col2 col3

1 16 21 26
2 17 22 27
3 18 23 28
4 19 24 29
5 20 25 30
rbind(samp1, samp2)

col1 col2 col3

1 1 6 11
2 2 7 12
3 3 8 13
4 4 9 14
5 5 10 15
6 16 21 26
7 17 22 27
8 18 23 28
9 19 24 29
10 20 25 30

1 2 3 7