# Post for R

4 messages
Open this post in threaded view
|

## Post for R

 Hello,  I want to split the dataframe into 1000 groups based on two column values(max value and second max value). First, I made two lists L1 and L2.  L1 is the list divided into 100 groups based on the range of max value and L2 is divided into 10 groups based on the second max values. Now I want to do the combinations based on L1 and L2. I want to do a for loop for L1 and for each element in L1, I split it into 10 groups based on L2. I tried to write the code, but it does not work. L1<-split(df,cut(df\$max,seq(0,1,by=0.01)))L2<-split(df,cut(df\$submax,seq(0,0.2,by=0.02))) Z<-list()G<-list()for (i in length(L1)){  Z=data.frame(L1[i])  G <- split(Z\$submax,"0.02")  print(G)  } Thanks so much!Carrie         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Post for R

 Carrie, I would suggest a few things before posting your code here: - Put a dput(df) - Format it properly, as it stands it won't compile, because you're missing newlines/semicolons between, e.g. Z <- list()*; *G <- list(); for (i in length(L1)){  Z=data.frame(L1[i])*;* G <- split(Z\$submax,"0.02")*;*  print(G)  } -- H On 31 May 2017 at 19:48, carrie wang via R-help <[hidden email]> wrote: > > Hello, > I want to split the dataframe into 1000 groups based on two column > values(max value and second max value). First, I made two lists L1 and L2. > L1 is the list divided into 100 groups based on the range of max value and > L2 is divided into 10 groups based on the second max values. Now I want to > do the combinations based on L1 and L2. I want to do a for loop for L1 and > for each element in L1, I split it into 10 groups based on L2. I tried to > write the code, but it does not work. > > L1<-split(df,cut(df\$max,seq(0,1,by=0.01)))L2<-split(df,cut(d > f\$submax,seq(0,0.2,by=0.02))) > Z<-list()G<-list()for (i in length(L1)){  Z=data.frame(L1[i])  G <- > split(Z\$submax,"0.02")  print(G)  } > Thanks so much!Carrie >         [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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/posti> ng-guide.html > and provide commented, minimal, self-contained, reproducible code. -- OpenPGP: https://sks-keyservers.net/pks/lookup?op=get&search=0xFEBAD7FFD041BBA1 If you wish to request my time, please do so using http://bit.ly/hd1ScheduleRequest. Si vous voudrais faire connnaisance, allez a http://bit.ly/hd1ScheduleRequest. Sent from my mobile device Envoye de mon portable         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.