[R] 'Split' character

Gabor Grothendieck ggrothendieck at gmail.com
Sun Nov 25 17:27:32 CET 2007


Try this using the BOD data frame that comes with R or
try using interaction in place of paste:

split(BOD, do.call(paste, c(BOD, sep = ":")), drop=TRUE)


On Nov 25, 2007 10:23 AM,  <pomchip at free.fr> wrote:
>
>
> Thanks Jim and Herinque for you reply.
>
> The substitution you are both proposing works fine, except when a or b contains
> decimal numbers (which is mostly my case in a real dataset). In this case, there
> is no distinction between the decimal point and the one introduced by the split
> function.
> If the split function cannot be customized, then I guess I have to first
> substitute the decimal point in my dataset by e.g. a * sign and change it back
> to a . when the split is done...
>
> Sebastien
>
> jim holtman a écrit :
>
> > Here is one way:
> >
> >> a<-1:10
> >> b<-21:30
> >> mydata<-data.frame(a,b)
> >> mydata.split<-split(mydata,(mydata[,1:2]),drop=TRUE)
> >> x <- mydata.split
> >> # customize the names
> >> names(x) <- sapply(strsplit(names(x), "\\."), paste, collapse="-my
> character-")
> >> x
> > $`1-my character-21`
> >   a  b
> > 1 1 21
> >
> > $`2-my character-22`
> >   a  b
> > 2 2 22
> >
> > $`3-my character-23`
> >   a  b
> > 3 3 23
> > ...........
> >
> > On Nov 24, 2007 6:15 PM,  <pomchip at free.fr> wrote:
> >>
> >> Dear R-users,
> >>
> >> The following code splits a very simple dataframe into a list, each element
> of
> >> the list being one line of the dataframe. You will see that the split
> function
> >> names each element of the list by using uses the content of a and b and
> merging
> >> them with a "." character. Is there a way to customize this character?
> >>
> >> a<-1:10
> >> b<-21:30
> >> mydata<-data.frame(a,b)
> >> mydata.split<-split(mydata,(mydata[,1:2]),drop=TRUE)
> >> mydata.split
> >>
> >> Thanks in advance for your help.
> >>
> >> Sebastien
> >>
> >> ______________________________________________
> >> 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.
> >>
> >
> >
> >
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list