[R] 'Split' character

jim holtman jholtman at gmail.com
Sun Nov 25 00:51:19 CET 2007


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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list