[R] rbind a heterogeneous row

Henrique Dallazuanna wwwhsd at gmail.com
Wed Mar 23 02:18:22 CET 2011


You need a list object indeed of a vector, try this:

rbind(df, dreps = c(rep(list(TRUE), 7), 5, 0))

On Tue, Mar 22, 2011 at 10:12 PM, Alexy Khrabrov <deliverable at gmail.com> wrote:
> I have a dataframe with many rows like this:
>
>> df
>                 X1   X2   X3   X4   X5   X6   X7 week         d
> sim1 FALSE TRUE TRUE TRUE TRUE TRUE TRUE    1 0.3064985
>
> sim1 is the rowname, X1..X7,week,d are the column names.  X1..X7 are factors, booleans in this case.
>
> I need to add another row, represented by the following list:
>
> list(rep(T,7),5,0.0)
>
> -- i.e, TRUE in all boolean columns, 5 in the week column, 0.0 in d.  The name of the new row is "dreps".
>
> I used to add fully numeric rows as follows:
>
> df1 <- rbind(df,dreps=c(<all numbers>))
>
> But if I do this here,
>
> df1 <- rbind(df,dreps=c(rep(T,7),5,0.0)) -- booleans are converted to 0/1, which is not what I want.
>
> What's the recommended way to specify and bind a heterogeneous row above?
>
> Cheers,
> Alexy
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list