Johannes Graumann
2007-Jul-18 09:40 UTC
[R] Subsetting Enigma: More rows after dataframe[-list,]?
Hello again, I'm trying to purge the indexes in i.delete from frame and end up with more rows!? Please be so kind and let me know where I screw this up ... Joh> i.delete[1] 40 45 165 212 253 270 280 287 301 352 421 433 463 467 487 [16] 517 537 542 573 594 596 612 614 621 635 650 696 699 707 732 [31] 738 776 826 891 892 936 937 935 940 976 988 995 1037 1043 1059 [46] 1081 1111 1123 1128 1132 1140 1153 1155 1165 1176 1179 1200 1281 1289 1300 [61] 1320 1346 1356 1366 1369 1396 1406 1420 1428 1429 1471 1474 1475 1525 1540 [76] 1554 1565 1645 1667 1665 1706 1711 1724 1764 1788 1791 1805 1808 1847 1881 [91] 10 18 137 238 254 260 262 288 292 314 338 349 414 447 457 [106] 465 470 478 511 530 536 552 582 588 644 655 687 693 701 724 [121] 739 763 771 836 848 859 888 900 902 919 939 972 979 989 1000 [136] 1002 1015 1020 1026 1029 1032 1055 1060 1073 1088 1104 1117 1124 1130 1135 [151] 1144 1221 1225 1249 1251 1257 1376 1384 1386 1453 1487 1529 1532 1534 1605 [166] 1624 1633 1646 1648 1702 1787 1948 1951> length(i.delete)[1] 173> nrow(frame)[1] 1975> nrow(frame[-i.delete,])[1] 1802
Gavin Simpson
2007-Jul-18 10:15 UTC
[R] Subsetting Enigma: More rows after dataframe[-list,]?
On Wed, 2007-07-18 at 11:40 +0200, Johannes Graumann wrote:> Hello again, > > I'm trying to purge the indexes in i.delete from frame and end up with more > rows!? Please be so kind and let me know where I screw this up ...I think you'll have to explain why you think there are more rows after using i.delete than before. (1975 - 173 = 1802). By purge, you mean delete the rows indexed by i.delete? If so, you are doing nothing wrong:> frame <- data.frame(matrix(runif(1975*10), ncol = 10)) > i.delete <- sample(nrow(frame), 173) # random rows to delete > nrow(frame)[1] 1975> nrow(frame[-i.delete, ])[1] 1802> nrow(frame) > nrow(frame[-i.delete, ])[1] TRUE G> > Joh > > > i.delete > [1] 40 45 165 212 253 270 280 287 301 352 421 433 463 467 > 487 > [16] 517 537 542 573 594 596 612 614 621 635 650 696 699 707 > 732 > [31] 738 776 826 891 892 936 937 935 940 976 988 995 1037 1043 > 1059 > [46] 1081 1111 1123 1128 1132 1140 1153 1155 1165 1176 1179 1200 1281 1289 > 1300 > [61] 1320 1346 1356 1366 1369 1396 1406 1420 1428 1429 1471 1474 1475 1525 > 1540 > [76] 1554 1565 1645 1667 1665 1706 1711 1724 1764 1788 1791 1805 1808 1847 > 1881 > [91] 10 18 137 238 254 260 262 288 292 314 338 349 414 447 > 457 > [106] 465 470 478 511 530 536 552 582 588 644 655 687 693 701 > 724 > [121] 739 763 771 836 848 859 888 900 902 919 939 972 979 989 > 1000 > [136] 1002 1015 1020 1026 1029 1032 1055 1060 1073 1088 1104 1117 1124 1130 > 1135 > [151] 1144 1221 1225 1249 1251 1257 1376 1384 1386 1453 1487 1529 1532 1534 > 1605 > [166] 1624 1633 1646 1648 1702 1787 1948 1951 > > > length(i.delete) > [1] 173 > > > nrow(frame) > [1] 1975 > > > nrow(frame[-i.delete,]) > [1] 1802 > > ______________________________________________ > R-help at stat.math.ethz.ch 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.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
J.delasHeras at ed.ac.uk
2007-Jul-18 18:07 UTC
[R] Subsetting Enigma: More rows after dataframe[-list,]?
Quoting Johannes Graumann <johannes_graumann at web.de>:> Hello again, > > I'm trying to purge the indexes in i.delete from frame and end up with more > rows!? Please be so kind and let me know where I screw this up ... > > Joh > >> i.delete > [1] 40 45 165 212 253 270 280 287 301 352 421 433 463 467 > 487 > [16] 517 537 542 573 594 596 612 614 621 635 650 696 699 707 > 732 > [31] 738 776 826 891 892 936 937 935 940 976 988 995 1037 1043 > 1059 > [46] 1081 1111 1123 1128 1132 1140 1153 1155 1165 1176 1179 1200 1281 1289 > 1300 > [61] 1320 1346 1356 1366 1369 1396 1406 1420 1428 1429 1471 1474 1475 1525 > 1540 > [76] 1554 1565 1645 1667 1665 1706 1711 1724 1764 1788 1791 1805 1808 1847 > 1881 > [91] 10 18 137 238 254 260 262 288 292 314 338 349 414 447 > 457 > [106] 465 470 478 511 530 536 552 582 588 644 655 687 693 701 > 724 > [121] 739 763 771 836 848 859 888 900 902 919 939 972 979 989 > 1000 > [136] 1002 1015 1020 1026 1029 1032 1055 1060 1073 1088 1104 1117 1124 1130 > 1135 > [151] 1144 1221 1225 1249 1251 1257 1376 1384 1386 1453 1487 1529 1532 1534 > 1605 > [166] 1624 1633 1646 1648 1702 1787 1948 1951 > >> length(i.delete) > [1] 173 > >> nrow(frame) > [1] 1975 > >> nrow(frame[-i.delete,]) > [1] 1802Hmmm... i.delete is a vector with 173 elements (indices). frame has originally 1975 rows, then you remove 173 (i.delete) and you end up with a new frame with 1802 rows (1975-173). It works as expected... you get LESS rows afterwards, not more. (?) :-) Jose -- Dr. Jose I. de las Heras Email: J.delasHeras at ed.ac.uk The Wellcome Trust Centre for Cell Biology Phone: +44 (0)131 6513374 Institute for Cell & Molecular Biology Fax: +44 (0)131 6507360 Swann Building, Mayfield Road University of Edinburgh Edinburgh EH9 3JR UK
Maybe Matching Threads
- group data in classes
- extract values
- ggplot2, geomtile fill assignment
- Question about error of "non-numeric argument to binary operator"
- 14 commits - libswfdec/swfdec_as_object.c libswfdec/swfdec_file_reference.c libswfdec/swfdec_load_object.c libswfdec/swfdec_sprite_movie_as.c libswfdec/swfdec_system_security.c test/trace