[R] help requested
jim holtman
jholtman at gmail.com
Sat Dec 11 23:43:55 CET 2010
try this:
> x
X1 X2
1 1 3
2 1 4
3 1 5
4 2 3
5 2 4
6 3 2
7 4 1
8 4 3
9 4 5
10 5 2
11 5 4
> sapply(split(x, x$X1), function(.grp){
+ paste(.grp[[1]][1], paste(.grp[[2]], collapse = ','))
+ })
1 2 3 4 5
"1 3,4,5" "2 3,4" "3 2" "4 1,3,5" "5 2,4"
>
On Fri, Dec 10, 2010 at 11:20 AM, Jinyan Huang <jinyan.fr at gmail.com> wrote:
> awk '{arr[$1]=arr[$1] " " $2}END{for( i in arr){print i,arr[i]}}'
> edgelist.txt | sort -k1
>
>
>
> On Fri, Dec 10, 2010 at 4:20 PM, profaar <profaar at live.com> wrote:
>> 1 2
>> 1 3
>> 1 4
>> 1 5
>> 2 3
>> 2 4
>> 3 2
>> 4 1
>> 4 3
>> 4 5
>> 5 2
>> 5 4
>
> ______________________________________________
> 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
Data Munger Guru
What is the problem that you are trying to solve?
More information about the R-help
mailing list