Vote count:
0
Let's say I have a data frame "x"
> x
x1 x2 x3
1 box 0.81432465 4
2 box 0.19628122 2
3 box 0.06619734 1
4 box 0.90403568 5
5 box 0.52693274 3
6 axe 0.28665840 2
7 axe 0.45193228 3
8 axe 0.48278466 4
9 axe 0.86553847 5
10 axe 0.13925190 1
11 cat 0.86340413 5
12 cat 0.28387540 2
13 cat 0.24297445 1
14 cat 0.36651366 3
15 cat 0.55038108 4
Then I perform following operations on it
> x.factor <- factor(x[,1]) ## convert column 1 as factors
> x.split <- split(x, x.factor)
> unsplit(x.split, x.factor) ## get back original data frame
works fine till now. But when I do this, it gives me an error
> x.split2 <- lapply(x.split, function(x) {head(x,1)})
> unsplit(x.split2, x.factor) ## trying to combine into a data frame
Error in `row.names<-.data.frame`(`*tmp*`, value = value) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘1’, ‘11’, ‘6’
I don't get it because, if I print out x.split2, the row names are unique for each element in the list.
Why am I getting this error?
asked 1 min ago
Aucun commentaire:
Enregistrer un commentaire