How to Add new row to DataFrame in R

Suppose your dataSet is Cats, given in the MASS library.

If you want to load then type following commands in R console

>library(MASS)

>Cats

So you have loaded dataset, Cats which is similar to below one

Sex Bwt Hwt
1 F 2.0 7.0
2 F 2.0 7.4
3 F 2.0 9.5

Now if you want to add new Row to existing one.
1) First, create new row for dataFrame

> newRow <- data.frame(Sex=’F’,Bwt=2.1,Hwt=8.1)

>Cats <- rbind(Cats,newRow)

Thats it!!!!!

Type
>Cats

You will see new row appended to the existing data


Leave a Reply

Your email address will not be published. Required fields are marked *