Re: [R] Predicted values from glm() when linear predictor is NA.

2022-07-27 Thread Jeff Newmiller
But "disappearing" is not what NA is supposed to do normally. Why is it being 
treated that way here?

On July 27, 2022 7:04:20 PM PDT, John Fox  wrote:
>Dear Rolf,
>
>The coefficient of TrtTime:LifestageL1 isn't estimable (as you explain) and by 
>setting it to NA, glm() effectively removes it from the model. An equivalent 
>model is therefore
>
>> fit2 <- glm(cbind(Dead,Alive) ~ TrtTime + Lifestage +
>+   I((Lifestage == "Egg + L1")*TrtTime) +
>+   I((Lifestage == "L1 + L2")*TrtTime) +
>+   I((Lifestage == "L3")*TrtTime),
>+ family=binomial, data=demoDat)
>Warning message:
>glm.fit: fitted probabilities numerically 0 or 1 occurred
>
>> cbind(coef(fit, complete=FALSE), coef(fit2))
>  [,1] [,2]
>(Intercept)-0.91718302  -0.91718302
>TrtTime 0.88846195   0.88846195
>LifestageEgg + L1 -45.36420974 -45.36420974
>LifestageL114.27570572  14.27570572
>LifestageL1 + L2   -0.30332697  -0.30332697
>LifestageL3-3.58672631  -3.58672631
>TrtTime:LifestageEgg + L1   8.10482459   8.10482459
>TrtTime:LifestageL1 + L20.05662651   0.05662651
>TrtTime:LifestageL3 1.66743472   1.66743472
>
>There is no problem computing fitted values for the model, specified either 
>way. That the fitted values when Lifestage == "L1" all round to 1 on the 
>probability scale is coincidental -- that is, a consequence of the data.
>
>I hope this helps,
> John
>
>On 2022-07-27 8:26 p.m., Rolf Turner wrote:
>> 
>> I have a data frame with a numeric ("TrtTime") and a categorical
>> ("Lifestage") predictor.
>> 
>> Level "L1" of Lifestage occurs only with a single value of TrtTime,
>> explicitly 12, whence it is not possible to estimate a TrtTime "slope"
>> when Lifestage is "L1".
>> 
>> Indeed, when I fitted the model
>> 
>>  fit <- glm(cbind(Dead,Alive) ~ TrtTime*Lifestage, family=binomial,
>> data=demoDat)
>> 
>> I got:
>> 
>>> as.matrix(coef(fit))
>>>[,1]
>>> (Intercept)-0.91718302
>>> TrtTime 0.88846195
>>> LifestageEgg + L1 -45.36420974
>>> LifestageL114.27570572
>>> LifestageL1 + L2   -0.30332697
>>> LifestageL3-3.58672631
>>> TrtTime:LifestageEgg + L1   8.10482459
>>> TrtTime:LifestageL1 NA
>>> TrtTime:LifestageL1 + L20.05662651
>>> TrtTime:LifestageL3 1.66743472
>> 
>> That is, TrtTime:LifestageL1 is NA, as expected.
>> 
>> I would have thought that fitted or predicted values corresponding to
>> Lifestage = "L1" would thereby be NA, but this is not the case:
>> 
>>> predict(fit)[demoDat$Lifestage=="L1"]
>>>26   65  131
>>> 24.02007 24.02007 24.02007
>>> 
>>> fitted(fit)[demoDat$Lifestage=="L1"]
>>>   26  65 131
>>>1   1   1
>> 
>> That is, the predicted values on the scale of the linear predictor are
>> large and positive, rather than being NA.
>> 
>> What this amounts to, it seems to me, is saying that if the linear
>> predictor in a Binomial glm is NA, then "success" is a certainty.
>> This strikes me as being a dubious proposition.  My gut feeling is that
>> misleading results could be produced.
>> 
>> Can anyone explain to me a rationale for this behaviour pattern?
>> Is there some justification for it that I am not currently seeing?
>> Any other comments?  (Please omit comments to the effect of "You are as
>> thick as two short planks!". :-) )
>> 
>> I have attached the example data set in a file "demoDat.txt", should
>> anyone want to experiment with it.  The file was created using dput() so
>> you should access it (if you wish to do so) via something like
>> 
>>  demoDat <- dget("demoDat.txt")
>> 
>> Thanks for any enlightenment.
>> 
>> cheers,
>> 
>> Rolf Turner
>> 
>> 
>> __
>> R-help@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.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@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.


Re: [R] Predicted values from glm() when linear predictor is NA.

2022-07-27 Thread Rolf Turner


On Thu, 28 Jul 2022 00:42:51 +
"Ebert,Timothy Aaron"  wrote:

> Time is often used in this sort of problem, but really time is not
> relevant. A better choice is accumulated thermal units. The insect
> will molt when X thermal units have been accumulated. This is often
> expressed as degree days, but could as easily be other units like
> degree seconds. However, I suspect that fine time units exceeds the
> accuracy of the measurement system. A growth chamber might maintain
> 28 C, but the temperature the insect experiences might be somewhat
> different thereby introducing additional variability in the outcome.
> No thermal units accumulated, no development, so that is not an
> issue. This approach allows one to predict life stage over a large
> temperature range. Accuracy can be improved if one knows the lower
> development threshold. At high temperatures development stops, and a
> mortality function can be added.

Very cogent comments in respect of dealing with the underlying
practical problem, but I am not so much concerned with the practical
problem at the moment but rather with the workings of the software that
I am using.

cheers,

Rolf

P.S.  I am at several removes from the data set(s) that I am messing
about with.  But if my understanding is correct (always an assumption
of which to be sceptical!) these data were collected with the
temperature being held *constant*, whence time and accumulated thermal
units would be equivalent.  Is it not so?

R.

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@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.


Re: [R] Predicted values from glm() when linear predictor is NA.

2022-07-27 Thread John Fox

Dear Rolf,

The coefficient of TrtTime:LifestageL1 isn't estimable (as you explain) 
and by setting it to NA, glm() effectively removes it from the model. An 
equivalent model is therefore


> fit2 <- glm(cbind(Dead,Alive) ~ TrtTime + Lifestage +
+   I((Lifestage == "Egg + L1")*TrtTime) +
+   I((Lifestage == "L1 + L2")*TrtTime) +
+   I((Lifestage == "L3")*TrtTime),
+ family=binomial, data=demoDat)
Warning message:
glm.fit: fitted probabilities numerically 0 or 1 occurred

> cbind(coef(fit, complete=FALSE), coef(fit2))
  [,1] [,2]
(Intercept)-0.91718302  -0.91718302
TrtTime 0.88846195   0.88846195
LifestageEgg + L1 -45.36420974 -45.36420974
LifestageL114.27570572  14.27570572
LifestageL1 + L2   -0.30332697  -0.30332697
LifestageL3-3.58672631  -3.58672631
TrtTime:LifestageEgg + L1   8.10482459   8.10482459
TrtTime:LifestageL1 + L20.05662651   0.05662651
TrtTime:LifestageL3 1.66743472   1.66743472

There is no problem computing fitted values for the model, specified 
either way. That the fitted values when Lifestage == "L1" all round to 1 
on the probability scale is coincidental -- that is, a consequence of 
the data.


I hope this helps,
 John

On 2022-07-27 8:26 p.m., Rolf Turner wrote:


I have a data frame with a numeric ("TrtTime") and a categorical
("Lifestage") predictor.

Level "L1" of Lifestage occurs only with a single value of TrtTime,
explicitly 12, whence it is not possible to estimate a TrtTime "slope"
when Lifestage is "L1".

Indeed, when I fitted the model

 fit <- glm(cbind(Dead,Alive) ~ TrtTime*Lifestage, family=binomial,
data=demoDat)

I got:


as.matrix(coef(fit))
   [,1]
(Intercept)-0.91718302
TrtTime 0.88846195
LifestageEgg + L1 -45.36420974
LifestageL114.27570572
LifestageL1 + L2   -0.30332697
LifestageL3-3.58672631
TrtTime:LifestageEgg + L1   8.10482459
TrtTime:LifestageL1 NA
TrtTime:LifestageL1 + L20.05662651
TrtTime:LifestageL3 1.66743472


That is, TrtTime:LifestageL1 is NA, as expected.

I would have thought that fitted or predicted values corresponding to
Lifestage = "L1" would thereby be NA, but this is not the case:


predict(fit)[demoDat$Lifestage=="L1"]
   26   65  131
24.02007 24.02007 24.02007

fitted(fit)[demoDat$Lifestage=="L1"]
  26  65 131
   1   1   1


That is, the predicted values on the scale of the linear predictor are
large and positive, rather than being NA.

What this amounts to, it seems to me, is saying that if the linear
predictor in a Binomial glm is NA, then "success" is a certainty.
This strikes me as being a dubious proposition.  My gut feeling is that
misleading results could be produced.

Can anyone explain to me a rationale for this behaviour pattern?
Is there some justification for it that I am not currently seeing?
Any other comments?  (Please omit comments to the effect of "You are as
thick as two short planks!". :-) )

I have attached the example data set in a file "demoDat.txt", should
anyone want to experiment with it.  The file was created using dput() so
you should access it (if you wish to do so) via something like

 demoDat <- dget("demoDat.txt")

Thanks for any enlightenment.

cheers,

Rolf Turner


__
R-help@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.

--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

__
R-help@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.


Re: [R] Predicted values from glm() when linear predictor is NA.

2022-07-27 Thread David Winsemius



On 7/27/22 17:26, Rolf Turner wrote:

I have a data frame with a numeric ("TrtTime") and a categorical
("Lifestage") predictor.

Level "L1" of Lifestage occurs only with a single value of TrtTime,
explicitly 12, whence it is not possible to estimate a TrtTime "slope"
when Lifestage is "L1".

Indeed, when I fitted the model

 fit <- glm(cbind(Dead,Alive) ~ TrtTime*Lifestage, family=binomial,
data=demoDat)

I got:


as.matrix(coef(fit))
   [,1]
(Intercept)-0.91718302
TrtTime 0.88846195
LifestageEgg + L1 -45.36420974
LifestageL114.27570572
LifestageL1 + L2   -0.30332697
LifestageL3-3.58672631
TrtTime:LifestageEgg + L1   8.10482459
TrtTime:LifestageL1 NA
TrtTime:LifestageL1 + L20.05662651
TrtTime:LifestageL3 1.66743472

That is, TrtTime:LifestageL1 is NA, as expected.

I would have thought that fitted or predicted values corresponding to
Lifestage = "L1" would thereby be NA, but this is not the case:


predict(fit)[demoDat$Lifestage=="L1"]
   26   65  131
24.02007 24.02007 24.02007

fitted(fit)[demoDat$Lifestage=="L1"]
  26  65 131
   1   1   1

That is, the predicted values on the scale of the linear predictor are
large and positive, rather than being NA.

What this amounts to, it seems to me, is saying that if the linear
predictor in a Binomial glm is NA, then "success" is a certainty.
This strikes me as being a dubious proposition.  My gut feeling is that
misleading results could be produced.


The NA is most likely caused by aliasing, so some other combination of 
factors a perfect surrogate for every case with that level of the 
interaction. The `predict.glm` function always requires a complete set 
of values to construct a case. Whether apparent incremental linear 
prediction of that interaction term is large or small will depend on the 
degree of independent contribution of the surrogate levels of other 
variables..



David.



Can anyone explain to me a rationale for this behaviour pattern?
Is there some justification for it that I am not currently seeing?
Any other comments?  (Please omit comments to the effect of "You are as
thick as two short planks!". :-) )

I have attached the example data set in a file "demoDat.txt", should
anyone want to experiment with it.  The file was created using dput() so
you should access it (if you wish to do so) via something like

 demoDat <- dget("demoDat.txt")

Thanks for any enlightenment.

cheers,

Rolf Turner


__
R-help@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.


__
R-help@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.


Re: [R] Need to insert various rows of data from a data frame after particular rows from another dataframe

2022-07-27 Thread avi.e.gross
Ranjeet,

As others have said, you have not shown enough to get decent answers.

What you describe sounds quite routine and is the first step many have to do 
when gathering data from disparate sources that were done by different people 
without much consideration it has to follow some specific pattern.

Every data frame has umpteen columns with names in some order and containing 
data in each column that is of some type.

So if you want to combine them vertically using something like rbind() then you 
must make sure the two align exactly.

You could do a names(df1) and names(df2) to see what you have. If both do not 
have the same number of columns, you may want to either delete some in one or 
add to the other. If the names of some columns are not exactly the same, rename 
them. If the order is not the same, reorder them. This is fairly simple stuff 
you can do in base R or in something like dplyr and is a standard part of 
getting data into a form you want.

A tad more subtle is the need for conversions if the above is not working for 
you. If one file has text where the other has integers, then convert one or the 
other. If one is all uppercase and the other not, again, you need to make the 
same if it matters. For rbind() not immediately but for some kind of merge or 
join, definitely. If your data already is stored as a factor, be careful if the 
two do not line up with the same factors.

Again, without some details that show how the two are not already aligned, it 
is up to you to do the work, step by step, until they are.

Of course there are other approaches that can make this less painful. You can 
simply make a NEW df dynamically like this:

newdf <- data.frame(alpha=c(df1$colx, df2$coly), beta=c(df1$..., df2$...), ...)

This concatenates vectors/columns rather than the entire data.frame and makes 
some sense if you want to keep just a few columns and the dataframes are 
otherwise in quite a scrambled order.

And just for correction, when you say your data is in EXCEL, generally that 
does not mean a .CSV file but a .XSLX file and that would be opened and read 
another way.


-Original Message-
From: R-help  On Behalf Of Ranjeet Kumar Jha
Sent: Wednesday, July 27, 2022 5:01 AM
To: PIKAL Petr 
Cc: R-help 
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.

__
R-help@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.


Re: [R] Need to insert various rows of data from a data frame after particular rows from another dataframe

2022-07-27 Thread Ebert,Timothy Aaron
I think what you want is full_join() from the dplyr package.
https://www.rdocumentation.org/packages/dplyr/versions/0.7.8/topics/join

The only requirement is that both data frames must have a column in common 
wherein the data are entered in the same way. So the column labeled "state" 
needs to have "ANANTAPUR" in both data frames rather than "ANANTAPUR" in one 
data frame and "Anantapur" in the other. 

Reformat your excel spreadsheet to remove headers. Your first column should be 
three columns: State, then Crop, then district rather than headings. The first 
row can contain variable names. I would make variable names simple (like "Area" 
and "Production") but some like more information so "Area_Ha" and 
"Production_TN_per_Ha" would also work. It is best not to use special symbols 
in variable names and keep variable names as one string of characters (no 
spaces). Including such will eventually cause problems.
https://www.w3schools.com/r/r_variables.asp#:~:text=Variable%20Names=Rules%20for%20R%20variables%20are,be%20followed%20by%20a%20digit.

One exception to the rules in the link is that you can make a variable name T 
or F. R defaults to interpreting these as TRUE and FALSE. The problem happens 
when the programmer reassigns these and then tries to use T or F as Boolean in 
other parts of the program.

Tim

-Original Message-
From: R-help  On Behalf Of Ranjeet Kumar Jha
Sent: Monday, July 25, 2022 9:03 AM
To: R-help 
Subject: [R] Need to insert various rows of data from a data frame after 
particular rows from another dataframe

[External Email]

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://urldefense.proofpoint.com/v2/url?u=https-3A__drive.google.com_drive_u_0_folders_1dNmGTI8-5Fc9PK1QqmfIjnpbyzuiCXgxFC=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=9B32l682GguXDLEFdPm6j5JZNatveGSlY7lnwLYFVOW2TX1tNLeHbDE49MYxSh_Q=4_bhl2_drIA0Pn3LHMcoAd02lX0t6bAx2wSlhVAJelA=

Please help solving this problem.

Regards and Thanks,
Ranjeet

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=9B32l682GguXDLEFdPm6j5JZNatveGSlY7lnwLYFVOW2TX1tNLeHbDE49MYxSh_Q=MAGsb78RBOWV0usgeNnmHsZcYoQI959dmihJ9Ycs8Lo=
PLEASE do read the posting guide 
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=9B32l682GguXDLEFdPm6j5JZNatveGSlY7lnwLYFVOW2TX1tNLeHbDE49MYxSh_Q=PSiyw67xhInkZo69l1HojQKGOqthbxYpGL5Q14cPo8w=
and provide commented, minimal, self-contained, reproducible code.

__
R-help@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.


Re: [R] Request concerning use in book

2022-07-27 Thread Ebert,Timothy Aaron
My understanding is that the only requirement is to give proper credit. This is 
necessary anyway as readers would need to know what packages were used and what 
version of R was used. In R there is the citation() function that returns the 
approved citation. However, it might be useful to also include the version 
numbers in the text. 

One problem is how the citation is viewed in the body of the document. I use 
Endnote and I think Endnote would view this as a name. So in the text I would 
see (Team 2022) and the bibliography might be Team, R.C. 2022. R: A language 
... 
I think that this is solved by putting a comma after Team in the bibliographic 
entry. Another option would be to use R_Core_Team.


If this is a well-funded project, you might consider a donation. I am sure that 
R would appreciate any donation you would care to give in support of their 
work: https://www.r-project.org/foundation/donors.html. They accept annual 
donations or one-off donations. 


Tim

-Original Message-
From: R-help  On Behalf Of karl.fu...@sbg.at
Sent: Monday, July 25, 2022 9:21 AM
To: r-help@r-project.org
Subject: [R] Request concerning use in book

[External Email]

Dear colleagues!



We plan to introduce the software R in chapter "subject-specific software in 
mathematics" in our book "TEACHING/LEARNING MEDIUM COMPUTER".



As we will use screenshots and Plots generated by R we ask if there will be any 
fees for using this elements in our book.



Yours

Dr. Karl Fuchs, Austria


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=A3HEHpcoQF1M1edkMCL9__nY4ZWvWCW-nbxP99mzSHx6iiEKfLuE840Se5Vgnb73=j_53saaRAJYoyNAVUDwyUpFsxg4UTGNuPl3zvxbAV50=
PLEASE do read the posting guide 
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=A3HEHpcoQF1M1edkMCL9__nY4ZWvWCW-nbxP99mzSHx6iiEKfLuE840Se5Vgnb73=0VJtv0PNkpCNdziw0p5jF61vrQAM5-OtH_dfP5dxbt8=
and provide commented, minimal, self-contained, reproducible code.

__
R-help@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.


Re: [R] Need to insert various rows of data from a data frame after particular rows from another dataframe

2022-07-27 Thread Ranjeet Kumar Jha
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  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  On Behalf Of Ranjeet Kumar
> Jha
> > Sent: Monday, July 25, 2022 3:03 PM
> > To: R-help 
> > 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]]
> >
> > __
> > R-help@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: *ranjeetjhaiit...@gmail.com *


*"Simple Heart, Humble Attitude and Surrender to Supreme Being make our
lives beautiful!"*

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Need to insert various rows of data from a data frame after particular rows from another dataframe

2022-07-27 Thread PIKAL Petr
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  
Sent: Wednesday, July 27, 2022 8:35 AM
To: PIKAL Petr 
Cc: R-help 
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.pi...@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   > On Behalf Of Ranjeet Kumar Jha
> Sent: Monday, July 25, 2022 3:03 PM
> To: R-help mailto:r-help@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]]
> 
> __
> R-help@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:   ranjeetjhaiit...@gmail.com





"Simple Heart, Humble Attitude and Surrender to Supreme Being make our lives 
beautiful!"



__
R-help@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.


Re: [R] Need to insert various rows of data from a data frame after particular rows from another dataframe

2022-07-27 Thread PIKAL Petr
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  On Behalf Of Ranjeet Kumar Jha
> Sent: Monday, July 25, 2022 3:03 PM
> To: R-help 
> 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]]
> 
> __
> R-help@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.
__
R-help@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.


Re: [R] Need to insert various rows of data from a data frame after particular rows from another dataframe

2022-07-27 Thread CALUM POLWART
Not very clear what you are trying to do. But I'd have thought possibly
dplyr left_join might be a solution for you.  The base R equivalent is
merge().

It might be a rbind or cbind can do it too.

On Wed, 27 Jul 2022, 03:30 Ranjeet Kumar Jha, 
wrote:

> 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_c9PK1QqmfIjnpbyzuiCXgxFC
>
> Please help solving this problem.
>
> Regards and Thanks,
> Ranjeet
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.