[R] match from a data.frame in dependence of an ID
Rui Barradas
ruipbarradas at sapo.pt
Fri Mar 28 16:42:44 CET 2014
Hello,
Maybe there are other ways but the following works.
tst2 <- matrix(nrow = dim(test)[1], ncol = dim(test)[2])
tst2[] <- test
tst2 <- cbind(dimnames(test)[[1]], tst2)
colnames(tst2) <- c("ID", dimnames(test)[[2]])
tst2 <- as.data.frame(tst2)
tst2
Hope this helps,
Rui Barradas
Em 28-03-2014 15:07, Mat escreveu:
> Thanks first. Your solutions works nearly perfect, i only have one problem
> left.
>
> The result looks like perfect, my problem is now, that i want to convert the
> solution into a data.frame.
>
> If i try
> test<-xtabs(df2$Value~df2$ID + df2$Group)
> test
> df2$Group
> df2$ID 1 2 3 4 5
> 10 10 20 30 40 50
> 11 0 0 60 70 0
> 12 0 0 0 80 0
>
> perfect.
>
> Now i try:
>
> test<-as.data.frame(test)
> test
> df2.ID df2.Group Freq
> 1 10 1 10
> 2 11 1 0
> 3 12 1 0
> 4 10 2 20
> 5 11 2 0
> 6 12 2 0
> 7 10 3 30
> 8 11 3 60
> 9 12 3 0
> 10 10 4 40
> 11 11 4 70
> 12 12 4 80
> 13 10 5 50
> 14 11 5 0
> 15 12 5 0
>
> Maybe i can delete the entries on the top "df2$Group" and "df2$ID"?
> My solution should like this one, that i can convert into a data.frame
>
>
> ID 1 2 3 4 5
> 1 10 10 20 30 40 50
> 2 11 0 0 60 70 0
> 3 12 0 0 0 80 0
>
> Thank you
> Mat
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/match-from-a-data-frame-in-dependence-of-an-ID-tp4687745p4687767.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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