[R] Insert row in specific location between data frames

David Winsemius dwinsemius at comcast.net
Fri Jun 29 21:31:02 CEST 2012


On Jun 29, 2012, at 2:48 PM, Peter Ehlers wrote:

> On 2012-06-29 11:29, David Winsemius wrote:
>>
>> On Jun 29, 2012, at 2:04 PM, Peter Ehlers wrote:
>>
>>>
>>> On 2012-06-29 10:01, pigpigmeow wrote:
>>>> Hi everyone! I have a simple question.
>>>>
>>>> my data is
>>>>  predict_SO2_a
>>>> 1       39.793231
>>>> 2       30.252578
>>>> 3       32.467584
>>>> 4       31.941509
>>>> 5       27.908320
>>>> 6       11.594137
>>>> 7        9.368125
>>>> 8       12.319093
>>>> 9       11.558811
>>>> 10       7.937192
>>>> 11      11.211306
>>>> 12      12.400342
>>>> 13      12.393146
>>>> 14      13.256160
>>>> 15      10.709600
>>>> 16       9.966334
>>>> 17      28.850652
>>>> 18      10.024405
>>>>
>>>>
>>>>
>>>> I want to insert row which is "NA" in 10th row
>>>
>>> Try this:
>>>
>>>  d<- data.frame(x = 101:118, y = rnorm(18))
>>>  d2<- data.frame(
>>>             rbind(head(d, 9), NA, tail(d, -9)),
>>>             row.names = NULL)
>>
>> That threw an error for me.
>> Error in do.call(f, cal0) : second argument must be a list
>
> ??
> Works fine for me on Windows Vista, bot 32/64-bit.

Seems to be the rbind call. MacOS / R 2.14.2
R version 2.14.2 (2012-02-29)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)


d2<- rbind(head(d, 9), NA, tail(d, -9))
Error in do.call(f, cal0) : second argument must be a list

>
> Also works for one-column dataframes.
>
> Peter
>
>>
>>   What about this?
>>
>> d[ c( 1:9, NA, 10:NROW(d) ), ]
>>
>> I do not like this behavior of "[" but I suppose it is useful  
>> sometimes.
>>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list