[R] Need to insert various rows of data from a data frame after particular rows from another dataframe
Ranjeet Kumar Jha
r@njeetjh@||tkgp @end|ng |rom gm@||@com
Thu Jul 28 09:56:52 CEST 2022
To check the error in columns when I use "intersection", it returns all the
8 columns. That means no difference in columns.
On Thu, Jul 28, 2022 at 1:12 PM Ranjeet Kumar Jha <
ranjeetjhaiitkgp using gmail.com> wrote:
> Hi Pikal,
>
> Now I have formatted the kharif data file in the same format as it is in
> the dacnet filecode:. However, "district.id" and "state.id " columns have
> "N/A" data that are appearing. If I use merge "rbind" function, it still
> throws this error:
>
> "Error in rbind(deparse.level, ...) :
> numbers of columns of arguments do not match"
>
> code:
> df3=rbind(kharif_18_19,dacnet_17)
> df3=df3[order(df3$district,df3$year),]
> x<-write.csv(df3,"df3.csv")
> view(x)
>
> On Wed, Jul 27, 2022 at 3:18 PM PIKAL Petr <petr.pikal using precheza.cz> wrote:
>
>> Hallo,
>>
>> I do not understand what you really want and you do not help much.
>>
>> No error, no data, vague description of your problem, no effort to
>> explain it better. Only you can see your data, only you can see the error
>> message so we are clueless.
>>
>> Cheers
>> Petr
>>
>>
>> From: Ranjeet Kumar Jha <ranjeetjhaiitkgp using gmail.com>
>> Sent: Wednesday, July 27, 2022 11:01 AM
>> To: PIKAL Petr <petr.pikal using precheza.cz>
>> Cc: R-help <r-help using r-project.org>
>> Subject: Re: [R] Need to insert various rows of data from a data frame
>> after particular rows from another dataframe
>>
>> yeah rbind works find bur dataframe 2 has different format and then rbind
>> can be used with first dataframe. But here I am struggling to bring the 2nd
>> dataframe in the same format as the 1st one.
>>
>> On Wed, Jul 27, 2022 at 1:13 PM PIKAL Petr <mailto:petr.pikal using precheza.cz>
>> wrote:
>> 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 <mailto:ranjeetjhaiitkgp using gmail.com>
>> Sent: Wednesday, July 27, 2022 8:35 AM
>> To: PIKAL Petr <mailto:petr.pikal using precheza.cz>
>> Cc: R-help <mailto:r-help using 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 <mailto:
>> petr.pikal using precheza.cz> wrote:
>> Hi.
>>
>> From what you say, plain "rbind" could be used, if the columns in both
>> sets
>> 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
>>
>> > -----Original Message-----
>> > From: R-help <mailto:r-help-bounces using r-project.org> On Behalf Of
>> Ranjeet Kumar Jha
>> > Sent: Monday, July 25, 2022 3:03 PM
>> > To: R-help <mailto:r-help using r-project.org>
>> > Subject: [R] Need to insert various rows of data from a data frame after
>> > particular rows from another dataframe
>> >
>> > Hello Everyone,
>> >
>> > I have dataset in a particular format in "dacnet_yield_update till
>> 2019.xlsx" file,
>> > where I need to insert the data of rows 2018-2019 and
>> > 2019-2020 for the districts those data are available in "Kharif crops
>> yield_18-
>> > 19.xlsx". I need to insert these two rows of data belonging to every
>> district, if
>> > data is available in a later excel file, just after the particular crop
>> group data for
>> > the particular district.
>> >
>> > I have put the data file in the given link.
>> > https://drive.google.com/drive/u/0/folders/1dNmGTI8_c9PK1QqmfIjnpbyzuiC
>> > XgxFC
>> >
>> > Please help solving this problem.
>> >
>> > Regards and Thanks,
>> > Ranjeet
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > mailto:R-help using r-project.org mailing list -- To UNSUBSCRIBE and more,
>> see
>> > 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.
>>
>>
>>
>> --
>> Ranjeet Kumar Jha, M.Tech. (IIT Kharagpur), Ph.D. (USA)
>> https://www.linkedin.com/in/ranjeet-kumar-jha-ph-d-usa-73a5aa56
>> -----------------------------------------------------------
>> Email: mailto:ranjeetjhaiitkgp using gmail.com
>>
>>
>> "Simple Heart, Humble Attitude and Surrender to Supreme Being make our
>> lives beautiful!"
>>
>>
>>
>>
>> --
>> Ranjeet Kumar Jha, M.Tech. (IIT Kharagpur), Ph.D. (USA)
>> https://www.linkedin.com/in/ranjeet-kumar-jha-ph-d-usa-73a5aa56
>> -----------------------------------------------------------
>> Email: mailto:ranjeetjhaiitkgp using gmail.com
>>
>>
>> "Simple Heart, Humble Attitude and Surrender to Supreme Being make our
>> lives beautiful!"
>>
>>
>
> --
> Ranjeet Kumar Jha, M.Tech. (IIT Kharagpur), Ph.D. (USA)
> https://www.linkedin.com/in/ranjeet-kumar-jha-ph-d-usa-73a5aa56
> -----------------------------------------------------------
> Email: *ranjeetjhaiitkgp using gmail.com <ranjeetjhaiitkgp using gmail.com>*
>
>
> *"Simple Heart, Humble Attitude and Surrender to Supreme Being make our
> lives beautiful!"*
>
>
--
Ranjeet Kumar Jha, M.Tech. (IIT Kharagpur), Ph.D. (USA)
https://www.linkedin.com/in/ranjeet-kumar-jha-ph-d-usa-73a5aa56
-----------------------------------------------------------
Email: *ranjeetjhaiitkgp using gmail.com <ranjeetjhaiitkgp using gmail.com>*
*"Simple Heart, Humble Attitude and Surrender to Supreme Being make our
lives beautiful!"*
[[alternative HTML version deleted]]
More information about the R-help
mailing list