Dear Contributors I would like to perform this operation using a loop, instead of repeating the same operation many times. The numbers from 1 to 4 related to different groups that are in the database and for which I have the same data. x<-c(1,3,7) datiP1 <- datiP[datiP$city ==1,x]; datiP2 <- datiP[datiP$city ==2,x]; datiP3 <- datiP[datiP$city ==3,x] datiP4 <- datiP[datiP$city ==4,x]; -- Thank you for any help you can provide. Francesca [[alternative HTML version deleted]]
Hi Francesca, Try something like this: x <- c(1, 3, 7) dati <- lapply(1:4, function(i) {datiP[datiP$city == i, x]}) dati[[1]] # datiP1 dati[[2]] # datiP2 dati[[3]] # datiP3 dati[[4]] # datiP4 if the *only* groups are 1, 2, 3, 4 (i.e., 1:4 is exhaustive), this can be simplified: dati <- by(datiP, datiP$city, `[`, x) For documentation, see: ?lapply ?by ?"[" # to see how I use the extraction operator as a function Hope this helps, Josh On Fri, Nov 11, 2011 at 12:24 PM, Francesca <francesca.pancotto at gmail.com> wrote:> Dear Contributors > I would like to perform this operation using a loop, instead of repeating > the same operation many times. > The numbers from 1 to 4 related to different groups that are in the > database and for which I have the same data. > > > ? ?x<-c(1,3,7) > > datiP1 <- datiP[datiP$city ==1,x]; > > datiP2 <- datiP[datiP$city ==2,x]; > > datiP3 <- datiP[datiP$city ==3,x] > > datiP4 <- datiP[datiP$city ==4,x]; > -- > > Thank you for any help you can provide. > > Francesca > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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. >-- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/
You've been told how to do what you ask. But I'm not convinced that you really want to do what you asked. It might be better to do whatever you want with the data leaving it all in one object. There are many ways of doing that, the 'by' function is one of them. On 11/11/2011 20:24, Francesca wrote:> Dear Contributors > I would like to perform this operation using a loop, instead of repeating > the same operation many times. > The numbers from 1 to 4 related to different groups that are in the > database and for which I have the same data. > > > x<-c(1,3,7) > > datiP1<- datiP[datiP$city ==1,x]; > > datiP2<- datiP[datiP$city ==2,x]; > > datiP3<- datiP[datiP$city ==3,x] > > datiP4<- datiP[datiP$city ==4,x];-- Patrick Burns pburns at pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno')
Hi all, I have the mean vector mu<- c(0,0) and variance sigma <- c(10,10), now how to sample from the bivariate normal density in R? Can some one suggest me? I did not fine the function "mvdnorm" in R. Best Gyan [[alternative HTML version deleted]]
On Nov 15, 2011, at 11:21 AM, Gyanendra Pokharel wrote:> Hi all, > I have the mean vector mu<- c(0,0) and variance sigma <- c(10,10), > now how > to sample from the bivariate normal density in R? > Can some one suggest me? > I did not fine the function "mvdnorm" in R.But when you typed ?mvdnorm R should have returned message to type ?? mvdnorm. I get a tone of on target "hits" when I do that. (... and I think you may not get as many hits because I have a bunch of package installed but there was a hit from MASS which I think is installed by default ....) -- David Winsemius, MD West Hartford, CT
hello mr martin i need the program of lower incomplet Gamma function, and i dont know any thing about mathematica, my gamma function is Y(1/2,r^2/4*teta), r is variable. pleasr help me, its emmidiate for me. all the best somaye node [[alternative HTML version deleted]]
I have no idea what you're talking about, and you're probably on the wrong mailing list. I'm sure there's Mathematica help out there. Sarah On Fri, Nov 18, 2011 at 10:53 AM, Somaye Node <somayenode at yahoo.com> wrote:> > Thanks for your reply, > i cant open three sites. > all the best. > > --- On Fri, 11/18/11, Sarah Goslee <sarah.goslee at gmail.com> wrote: > > From: Sarah Goslee <sarah.goslee at gmail.com> > Subject: Re: [R] help > To: "Somaye Node" <somayenode at yahoo.com> > Date: Friday, November 18, 2011, 12:20 PM > > I don't know a Mr. Martin, and this isn't a Mathematica list. Do you have an R question? > > On Friday, November 18, 2011, Somaye Node <somayenode at yahoo.com> wrote: > > hello mr martin > > i need the program of lower incomplet Gamma function, and i dont know any thing about mathematica, my gamma function is Y(1/2,r^2/4*teta), r is variable. > > pleasr help me, its emmidiate for me. > > all the best > > somaye node >-- Sarah Goslee http://www.functionaldiversity.org
I was wondering if anyone could help me with my R homework. I have using the R tutorials and help options but it just is not helping me at all. I have some questions completed but these are the ones i need help on: A.) Plot the values in vector MyNumbers in a scatterplot. B.) Create a new vector named NewNumbers, with values equal to four times those in MyNumbers plus a random number chosen from a normal distribution with mean 5 and standard deviation 3. C.) Plot MyNumbers against NewNumbers in a scatterplot. Find the slope and intercept using a linear model. Find out how much of the variance is due to your fit, and how much is due to the residuals. A.) An IQ test is normally distributed with a mean of 100 and a standard deviation of 15. n What score would be needed to be in the 95th percentile? B.) In what percentile would the score 112 fall? C.) What is the probability of getting a score that is exactly the mean? We measured test scores in 3 conditions, no studying, desperate studying, and studying well. There were 6 people in each condition. Perform an ANOVA on the data, with readable output, by doing the following: A.) Create a vector of these conditions (independent variable vector) that treats them as a factor. B.) No studying had mean 65 and standard deviation 8, desperate studying had mean 78 and standard deviation 3, and studying well had mean 90 and standard deviation 1. Create random data based on this information, and place it in a variable. C.) Perform an ANOVA on the data, with readable output. If anyone could help that would be greatly appreciated!! [[alternative HTML version deleted]]
>From the bottom of every email on this list:PLEASE do read the posting guide http://www.R-project.org/posting-guide.html And from the posting guide: Basic statistics and classroom homework: R-help is not intended for these. I'm not sure how being from your lab professor makes it any less applicable. Sarah On Fri, Dec 9, 2011 at 2:17 PM, <gauthiergabrielle at yahoo.com> wrote:> This actually is my homework from my lab professor, although I applaud her rude assumptions > Sent from my Verizon Wireless BlackBerry > > -----Original Message----- > From: Sarah Goslee <sarah.goslee at gmail.com> > Date: Fri, 9 Dec 2011 14:12:01 > To: Gabrielle Gauthier<gauthiergabrielle at yahoo.com> > Cc: <r-help at r-project.org> > Subject: Re: [R] HELP > > On Fri, Dec 9, 2011 at 1:35 PM, Gabrielle Gauthier > <gauthiergabrielle at yahoo.com> wrote: >> I was wondering if anyone could help me with my R homework. > > No. > > This list is not for doing homework, though I applaud your honesty in > admitting it. > > Your instructor is being paid to teach you; that's who you should be > consulting, rather than asking people on this list to help you cheat. > > Good luck, > Sarah > > > I have using the R tutorials and help options but it just is not > helping me at all. I have some questions completed but these are the > ones i need help on: >> A.) Plot the values in vector MyNumbers in a scatterplot. ? ? ? B.) Create a new vector named NewNumbers, with values equal to four times those in ? ? ?MyNumbers plus a random number chosen from a normal distribution with mean 5 and standard deviation 3. ?C.) Plot MyNumbers against NewNumbers in a scatterplot. Find the slope and intercept using a?linear model. Find out how much of the variance is due to your fit, and how much is due to the residuals. >> A.) An IQ test is normally distributed with a mean of 100 and a standard deviation of 15. n ? ? ? ? ? ? What?score would be needed to be in the 95th percentile? ? ? ? ?B.) In what percentile would the score 112 fall? ? ? ? ?C.) What is the probability of getting a score that is exactly the mean? >> We measured test scores in 3 conditions, no studying, desperate studying, and studying well. ? ?There were 6 people in each condition. Perform an ANOVA on the data, with readable output, by doing the following: ? ? ?A.) Create a vector of these conditions (independent variable vector) that treats them as a factor. ? ? B.) No studying had mean 65 and standard deviation 8, desperate studying had mean 78 and?standard deviation 3, and studying well had mean 90 and standard deviation 1. Create random ? ?data based on this information, and place it in a variable. ? ? C.) Perform an ANOVA on the data, with readable output. >> >> If anyone could help that would be greatly appreciated!! >> >>