Skip to content
Prev 392337 / 398502 Next

Need to insert various rows of data from a data frame after particular rows from another dataframe

Hi.

 

?is not working? is extremelly vague.

 

1.

What do you expect this code do?

 

for(cr in seq_along(dacnet_17$district)){

    match(arhar_18$district, dacnet_17$district)

}

 

See ?match and maybe also ??for? and try this

 

x <- letters[1:5]

y <- sample(letters, 100, replace=T)

match(x,y)

[1] 45 16 24 13 71

for(i in 1:3) match(x,y)

 

2.

rbind works as expeceted

 

arhar_18 <- data.frame(a=1:10, b=50, c=letters[1:10])

dacnet_17 <- data.frame(a=11:20, b=100, c=sample(letters,10))

df3=rbind(arhar_18,dacnet_17)

 

if your data has common column order and type.

 

To get more specific answer you need to ask specific question preferably with some data included (most preferably by dput command) and error message.

 

Cheers

Petr

 

 

From: Ranjeet Kumar Jha <ranjeetjhaiitkgp at gmail.com> 
Sent: Wednesday, July 27, 2022 8:35 AM
To: PIKAL Petr <petr.pikal at precheza.cz>
Cc: R-help <r-help at r-project.org>
Subject: Re: [R] Need to insert various rows of data from a data frame after particular rows from another dataframe

 

Hi Petr,

 

I used r-bind but it's not working.

Here is the code:

 

arhar_18<-read.csv("D:/Ranjeet/IAMV6/input/yield/kharif_18-19_yield/Kharif_2018/arhar_18.csv")

dacnet_17<-read.csv("D:/Ranjeet/IAMV6/input/yield/dacnet_yield_update till 2019.csv")

 

for(cr in seq_along(dacnet_17$district)){

    match(arhar_18$district, dacnet_17$district)

}

 

df3=rbind(arhar_18,dacnet_17)

df3=df3[order(df3$district,df3$year),]

x<-write.csv(df3,"df3.csv")

view(x)
On Wed, Jul 27, 2022 at 12:00 PM PIKAL Petr <petr.pikal at precheza.cz <mailto:petr.pikal at precheza.cz> > wrote:
Hi.
are the same and in the same order. After that you can reorder the resulting
data frame as you wish by "order". AFAIK for most functions row order in
data frame does not matter.

Cheers
Petr
2019.xlsx" file,
yield_18-
district, if
group data for
http://www.R-project.org/posting-guide.html

  
    

Thread (17 messages)

Ranjeet Kumar Jha Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 25 Calum Polwart Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 26 PIKAL Petr Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 26 Ranjeet Kumar Jha Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 26 Ranjeet Kumar Jha Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 26 Calum Polwart Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 26 PIKAL Petr Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 27 Ranjeet Kumar Jha Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 27 PIKAL Petr Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 27 Ebert,Timothy Aaron Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 27 @vi@e@gross m@iii@g oii gm@ii@com Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 27 Richard O'Keefe Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 27 Ranjeet Kumar Jha Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 28 Ranjeet Kumar Jha Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 28 Ranjeet Kumar Jha Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 28 Ranjeet Kumar Jha Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 28 PIKAL Petr Need to insert various rows of data from a data frame after particular rows from another dataframe Jul 28