Skip to content

Append data to vector form a column of a dataframe

3 messages · behave, Ivan Calandra, Wolfgang Wu

#
Dear R-community,

When doing this:
I expect something like:
but get:
the same for:

rbind(test[["a"]], 2)
or
rbind(as.vector(test[["a"]]), 2)
or
rbind(t(as.vector(test[["a"]])), 2)

Why is that and how do I extract the "values" from a dataframe to get the
desired result?

Thank you
Dom








--
View this message in context: http://r.789695.n4.nabble.com/Append-data-to-vector-form-a-column-of-a-dataframe-tp3897205p3897205.html
Sent from the R help mailing list archive at Nabble.com.
#
Hi Dom,

This is because "3" is recycled. It is necessary because the number of 
columns have to be the same for every row.

Try this instead:
c(test$a, 2)  ## you wrote "3" but meant "2" I guess

HTH,
Ivan

Le 10/12/2011 10:47, behave a ?crit :

  
    
#
In addition to Ivan, test$a is not a data.frame anymore but a numerical vector.
[1] "numeric"
[1] 1 2 3

So adding a row to your data.frame would be?
? a
1 1
2 2
3 3
4 2


?
Wolfgang Wu


----- Urspr?ngliche Message -----
Von: Ivan Calandra <ivan.calandra at uni-hamburg.de>
An: r-help at r-project.org
Cc: 
Gesendet: 11:19 Mittwoch, 12.Oktober 2011 
Betreff: Re: [R] Append data to vector form a column of a dataframe

Hi Dom,

This is because "3" is recycled. It is necessary because the number of 
columns have to be the same for every row.

Try this instead:
c(test$a, 2)? ## you wrote "3" but meant "2" I guess

HTH,
Ivan

Le 10/12/2011 10:47, behave a ?crit :