Sebastian Zeki
Sebastian Zeki

Reputation: 6874

How to add one row to a dataframe

Im not sure why a) I cant do this and b) I cant find the answer to this. All I want to do is add one row to a dataframe as follows
rbind(data.frame(Names = "FS", Values = 2377), result)

The dataframe is called result. The two columns in it are called Names and Values. When I run the above there is no error but also nothing gets added. Am I doing this correctly? The dataframe is as follows

   Names    Values
    (A)n    96
(AAATG)n    106
(AAGTG)n    19
(AATAG)n    2
(ACATG)n    28

The results I get are that the dataframe doesnt change at all

Upvotes: 0

Views: 205

Answers (1)

Devavrata
Devavrata

Reputation: 1785

Try this type of approach:-

x <- data.frame(Names="FS",Values=2377)
results <- data.frame(Names="SF",Values=10)
temp <- rbind(x,results)
print(temp)

It is working, first data frame has 1 row then after rbind row get addes to data frame. Results should be of same format.

>print(x)
  Names Values
1    SF     10
>print(temp)
  Names Values
1    FS   2377
2    SF     10

Upvotes: 1

Related Questions