[R] Insert row in specific location between data frames

Peter Ehlers ehlers at ucalgary.ca
Fri Jun 29 23:19:02 CEST 2012


On 2012-06-29 11:08, arun wrote:
> Hi,
>
> You can try this:
>
> dat1<-read.table(text="
> 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
> ",sep="",header=TRUE)
>
>   dat2<-dat1[10,]
>   dat2<-NA
> dat3<-data.frame(predict_SO2_a=c(dat1[1:9,],dat2,dat1[10:18,]))
>
> A.K.

But don't do this with more than one column in your dataframe.

Peter Ehlers

>
>
>
>
> ----- Original Message -----
> From: pigpigmeow <glorykwok at hotmail.com>
> To: r-help at r-project.org
> Cc:
> Sent: Friday, June 29, 2012 1:01 PM
> Subject: [R] Insert row in specific location between data frames
>
> 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
>
> that 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     NA
> ....
> and it becomes 19 rows in this data.
>
>
> however, I can't do this. my scipt is following
> topdata <- predict_SO2_a[1:10,]
> bottomdata <- predict_SO2_a[11:nrow(predict_SO2_a),]
> nadata <- data.frame(NA)
> d1 <- rbind(topdata,nadata)
> d2 <- rbind(d1, bottomdata)
>
> what is my problem?!
>
> Thank in advance!
>
>



More information about the R-help mailing list