Greetings R users, I am trying to renumber my groups within the file shown below. The groups are currently set as 8,9,10,etc. I would like to renumber this as 1,2,3,etc. I have searched the help files and only come across using the rownames to renumber the values but I need to match values. Any assistance is always appreciated, Regards, Charles structure(list(Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("NO", "YES" ), class = "factor"), Event_name = c(8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), Glucose.n = c(26, 3, 0, 26, 1, 25, 26, 25, 25, 26, 26, 25, 23, 23, 24, 24, 26, 26, 25, 25, 26, 26, 24, 21, 7, 12, 4, 0, 0, 4, 0, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1), Glucose.m = c(92.5, 90.3333333333333, NaN, 97.2307692307692, 116, 97.84, 107.653846153846, 105.32, 102.6, 94.6538461538462, 96.076923076923, 92.24, 87.5652173913043, 79.3913043478261, 81.2916666666667, 77.5, 75.9230769230769, 74.4615384615385, 72.68, 76.32, 74.9615384615385, 72.2307692307692, 92.5416666666667, 105.619047619048, 93.4285714285714, 96.5, 90, NaN, NaN, 86.5, NaN, 87, 90.25, 92.5, 98.75, 95.75, 94, 88.25, 54.3333333333333, 52, 74.5, 77.75, 81, 97.3333333333333, 82.5, 85, 66.5, 51, 81 ), Glucose.sd = c(18.9256439784753, 27.5922694487665, NA, 25.3050314242961, NA, 17.3917605012642, 21.027491163127, 12.0094407308029, 28.0728219695373, 17.7334538264655, 10.7700439253443, 12.7778454104490, 11.0075432274935, 14.6992242542214, 12.2739709270814, 10.9266328000819, 10.4457573279225, 13.1338669682033, 8.2194890352138, 19.9556174213344, 17.6079090620795, 10.9299869800753, 19.3052801217623, 29.7883806046522, 17.2032665779607, 18.4563366797521, 18.0554700852678, NA, NA, 19.7399763593239, NA, 22.3159136044214, 28.5116935075184, 21.7638844572072, 12.2848144742469, 12.0933866224478, 15.5777619273972, 11.842719282327, 39.1066916694999, 32.0936130717624, 66.8755062286136, 53.7796429887741, 17.6918060129541, 11.5902257671425, 34.6482322781408, 9.89949493661167, 26.1629509039023, NA, NA), Glucose.se = c(3.71162415205983, 15.9304041937980, NA, 4.96272496248326, NA, 3.47835210025284, 4.12383029856479, 2.40188814616057, 5.61456439390745, 3.47781642709786, 2.11217938990701, 2.55556908208981, 2.29523142628873, 3.06500013246251, 2.50541382409208, 2.23038958057991, 2.04858155574352, 2.57576322922309, 1.64389780704276, 3.99112348426689, 3.45319507311964, 2.14354680364304, 3.94067380331773, 6.50035756909396, 6.50222358617618, 5.32788547515463, 9.0277350426339, NA, NA, 9.86998817966195, NA, 11.1579568022107, 14.2558467537592, 10.8819422286036, 6.14240723712346, 6.04669331122391, 7.78888096369861, 5.92135964116351, 22.5782589625015, 16.0468065358812, 33.4377531143068, 26.8898214943871, 10.2143689640297, 6.69161996662824, 24.5, 7, 18.5, NA, NA)), .Names c("Group", "Event_name", "Glucose.n", "Glucose.m", "Glucose.sd", "Glucose.se" ), row.names = c(9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L), class = "data.frame") [[alternative HTML version deleted]]
Hi, It isn't entirely clear what you want, because it seems too simple. And most of your sample data are irrelevant, aren't they? Why not just use: testdata$Event_name2 <- testdata$Event_name - 7 Or you could try: testdata$Event_name3 <- as.numeric(as.factor(testdata$Event_name)) which will make the values into consecutive integers. Event_name Event_name2 Event_name3 9 8 1 1 10 9 2 2 11 10 3 3 12 11 4 4 13 12 5 5 14 13 6 6 15 14 7 7 16 15 8 8 17 16 9 9 18 17 10 10 19 18 11 11 20 19 12 12 21 20 13 13 22 21 14 14 23 22 15 15 24 23 16 16 25 24 17 17 26 25 18 18 27 26 19 19 28 27 20 20 29 28 21 21 30 29 22 22 31 30 23 23 32 31 24 24 33 33 26 25 34 34 27 26 41 8 1 1 42 9 2 2 43 10 3 3 44 11 4 4 45 12 5 5 46 13 6 6 47 14 7 7 48 15 8 8 49 16 9 9 50 17 10 10 51 18 11 11 52 19 12 12 53 20 13 13 54 21 14 14 55 22 15 15 56 23 16 16 57 24 17 17 58 25 18 18 59 26 19 19 60 27 20 20 61 28 21 21 62 29 22 22 63 30 23 23 On Mon, Jan 7, 2013 at 11:41 AM, Charles Determan Jr <deter088 at umn.edu> wrote:> Greetings R users, > > I am trying to renumber my groups within the file shown below. The groups > are currently set as 8,9,10,etc. I would like to renumber this as > 1,2,3,etc. I have searched the help files and only come across using the > rownames to renumber the values but I need to match values. Any assistance > is always appreciated, > > Regards, > Charles > > structure(list(Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("NO", "YES" > ), class = "factor"), Event_name = c(8, 9, 10, 11, 12, 13, 14, > 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, > 31, 33, 34, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, > 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), Glucose.n = c(26, 3, > 0, 26, 1, 25, 26, 25, 25, 26, 26, 25, 23, 23, 24, 24, 26, 26, > 25, 25, 26, 26, 24, 21, 7, 12, 4, 0, 0, 4, 0, 4, 4, 4, 4, 4, > 4, 4, 3, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1), Glucose.m = c(92.5, > 90.3333333333333, > NaN, 97.2307692307692, 116, 97.84, 107.653846153846, 105.32, > 102.6, 94.6538461538462, 96.076923076923, 92.24, 87.5652173913043, > 79.3913043478261, 81.2916666666667, 77.5, 75.9230769230769, > 74.4615384615385, > 72.68, 76.32, 74.9615384615385, 72.2307692307692, 92.5416666666667, > 105.619047619048, 93.4285714285714, 96.5, 90, NaN, NaN, 86.5, > NaN, 87, 90.25, 92.5, 98.75, 95.75, 94, 88.25, 54.3333333333333, > 52, 74.5, 77.75, 81, 97.3333333333333, 82.5, 85, 66.5, 51, 81 > ), Glucose.sd = c(18.9256439784753, 27.5922694487665, NA, 25.3050314242961, > NA, 17.3917605012642, 21.027491163127, 12.0094407308029, 28.0728219695373, > 17.7334538264655, 10.7700439253443, 12.7778454104490, 11.0075432274935, > 14.6992242542214, 12.2739709270814, 10.9266328000819, 10.4457573279225, > 13.1338669682033, 8.2194890352138, 19.9556174213344, 17.6079090620795, > 10.9299869800753, 19.3052801217623, 29.7883806046522, 17.2032665779607, > 18.4563366797521, 18.0554700852678, NA, NA, 19.7399763593239, > NA, 22.3159136044214, 28.5116935075184, 21.7638844572072, 12.2848144742469, > 12.0933866224478, 15.5777619273972, 11.842719282327, 39.1066916694999, > 32.0936130717624, 66.8755062286136, 53.7796429887741, 17.6918060129541, > 11.5902257671425, 34.6482322781408, 9.89949493661167, 26.1629509039023, > NA, NA), Glucose.se = c(3.71162415205983, 15.9304041937980, NA, > 4.96272496248326, NA, 3.47835210025284, 4.12383029856479, 2.40188814616057, > 5.61456439390745, 3.47781642709786, 2.11217938990701, 2.55556908208981, > 2.29523142628873, 3.06500013246251, 2.50541382409208, 2.23038958057991, > 2.04858155574352, 2.57576322922309, 1.64389780704276, 3.99112348426689, > 3.45319507311964, 2.14354680364304, 3.94067380331773, 6.50035756909396, > 6.50222358617618, 5.32788547515463, 9.0277350426339, NA, NA, > 9.86998817966195, NA, 11.1579568022107, 14.2558467537592, 10.8819422286036, > 6.14240723712346, 6.04669331122391, 7.78888096369861, 5.92135964116351, > 22.5782589625015, 16.0468065358812, 33.4377531143068, 26.8898214943871, > 10.2143689640297, 6.69161996662824, 24.5, 7, 18.5, NA, NA)), .Names > c("Group", > "Event_name", "Glucose.n", "Glucose.m", "Glucose.sd", "Glucose.se" > ), row.names = c(9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, > 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, > 31L, 32L, 33L, 34L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, > 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, > 63L), class = "data.frame") >-- Sarah Goslee http://www.functionaldiversity.org
Hello, I'm not sure I understand. Do you want to renumber column Event_name starting at 1? If so the following does the job. dat$Event_name <- dat$Event_name - min(dat$Event_name) + 1 Hope this helps, Rui Barradas Em 07-01-2013 16:41, Charles Determan Jr escreveu:> Greetings R users, > > I am trying to renumber my groups within the file shown below. The groups > are currently set as 8,9,10,etc. I would like to renumber this as > 1,2,3,etc. I have searched the help files and only come across using the > rownames to renumber the values but I need to match values. Any assistance > is always appreciated, > > Regards, > Charles > > structure(list(Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("NO", "YES" > ), class = "factor"), Event_name = c(8, 9, 10, 11, 12, 13, 14, > 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, > 31, 33, 34, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, > 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), Glucose.n = c(26, 3, > 0, 26, 1, 25, 26, 25, 25, 26, 26, 25, 23, 23, 24, 24, 26, 26, > 25, 25, 26, 26, 24, 21, 7, 12, 4, 0, 0, 4, 0, 4, 4, 4, 4, 4, > 4, 4, 3, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1), Glucose.m = c(92.5, > 90.3333333333333, > NaN, 97.2307692307692, 116, 97.84, 107.653846153846, 105.32, > 102.6, 94.6538461538462, 96.076923076923, 92.24, 87.5652173913043, > 79.3913043478261, 81.2916666666667, 77.5, 75.9230769230769, > 74.4615384615385, > 72.68, 76.32, 74.9615384615385, 72.2307692307692, 92.5416666666667, > 105.619047619048, 93.4285714285714, 96.5, 90, NaN, NaN, 86.5, > NaN, 87, 90.25, 92.5, 98.75, 95.75, 94, 88.25, 54.3333333333333, > 52, 74.5, 77.75, 81, 97.3333333333333, 82.5, 85, 66.5, 51, 81 > ), Glucose.sd = c(18.9256439784753, 27.5922694487665, NA, 25.3050314242961, > NA, 17.3917605012642, 21.027491163127, 12.0094407308029, 28.0728219695373, > 17.7334538264655, 10.7700439253443, 12.7778454104490, 11.0075432274935, > 14.6992242542214, 12.2739709270814, 10.9266328000819, 10.4457573279225, > 13.1338669682033, 8.2194890352138, 19.9556174213344, 17.6079090620795, > 10.9299869800753, 19.3052801217623, 29.7883806046522, 17.2032665779607, > 18.4563366797521, 18.0554700852678, NA, NA, 19.7399763593239, > NA, 22.3159136044214, 28.5116935075184, 21.7638844572072, 12.2848144742469, > 12.0933866224478, 15.5777619273972, 11.842719282327, 39.1066916694999, > 32.0936130717624, 66.8755062286136, 53.7796429887741, 17.6918060129541, > 11.5902257671425, 34.6482322781408, 9.89949493661167, 26.1629509039023, > NA, NA), Glucose.se = c(3.71162415205983, 15.9304041937980, NA, > 4.96272496248326, NA, 3.47835210025284, 4.12383029856479, 2.40188814616057, > 5.61456439390745, 3.47781642709786, 2.11217938990701, 2.55556908208981, > 2.29523142628873, 3.06500013246251, 2.50541382409208, 2.23038958057991, > 2.04858155574352, 2.57576322922309, 1.64389780704276, 3.99112348426689, > 3.45319507311964, 2.14354680364304, 3.94067380331773, 6.50035756909396, > 6.50222358617618, 5.32788547515463, 9.0277350426339, NA, NA, > 9.86998817966195, NA, 11.1579568022107, 14.2558467537592, 10.8819422286036, > 6.14240723712346, 6.04669331122391, 7.78888096369861, 5.92135964116351, > 22.5782589625015, 16.0468065358812, 33.4377531143068, 26.8898214943871, > 10.2143689640297, 6.69161996662824, 24.5, 7, 18.5, NA, NA)), .Names > c("Group", > "Event_name", "Glucose.n", "Glucose.m", "Glucose.sd", "Glucose.se" > ), row.names = c(9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, > 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, > 31L, 32L, 33L, 34L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, > 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, > 63L), class = "data.frame") > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
On Jan 7, 2013, at 8:41 AM, Charles Determan Jr wrote:> Greetings R users, > > I am trying to renumber my groups within the file shown below. The > groups > are currently set as 8,9,10,etc. I would like to renumber this as > 1,2,3,etc. I have searched the help files and only come across > using the > rownames to renumber the values but I need to match values. Any > assistance > is always appreciated,Assuming you mean the `Event_name` column rather than the `Groups` column which currently is a factor with label values of "YES" and "NO", then why not: dfrm$Event_name column <- dfrm$Event_name - 7 -- David.> > Regards, > Charles > > structure(list(Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("NO", "YES" > ), class = "factor"), Event_name = c(8, 9, 10, 11, 12, 13, 14, > 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, > 31, 33, 34, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, > 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), Glucose.n = c(26, 3, > 0, 26, 1, 25, 26, 25, 25, 26, 26, 25, 23, 23, 24, 24, 26, 26, > 25, 25, 26, 26, 24, 21, 7, 12, 4, 0, 0, 4, 0, 4, 4, 4, 4, 4, > 4, 4, 3, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1), Glucose.m = c(92.5, > 90.3333333333333, > NaN, 97.2307692307692, 116, 97.84, 107.653846153846, 105.32, > 102.6, 94.6538461538462, 96.076923076923, 92.24, 87.5652173913043, > 79.3913043478261, 81.2916666666667, 77.5, 75.9230769230769, > 74.4615384615385, > 72.68, 76.32, 74.9615384615385, 72.2307692307692, 92.5416666666667, > 105.619047619048, 93.4285714285714, 96.5, 90, NaN, NaN, 86.5, > NaN, 87, 90.25, 92.5, 98.75, 95.75, 94, 88.25, 54.3333333333333, > 52, 74.5, 77.75, 81, 97.3333333333333, 82.5, 85, 66.5, 51, 81 > ), Glucose.sd = c(18.9256439784753, 27.5922694487665, NA, > 25.3050314242961, > NA, 17.3917605012642, 21.027491163127, 12.0094407308029, > 28.0728219695373, > 17.7334538264655, 10.7700439253443, 12.7778454104490, > 11.0075432274935, > 14.6992242542214, 12.2739709270814, 10.9266328000819, > 10.4457573279225, > 13.1338669682033, 8.2194890352138, 19.9556174213344, 17.6079090620795, > 10.9299869800753, 19.3052801217623, 29.7883806046522, > 17.2032665779607, > 18.4563366797521, 18.0554700852678, NA, NA, 19.7399763593239, > NA, 22.3159136044214, 28.5116935075184, 21.7638844572072, > 12.2848144742469, > 12.0933866224478, 15.5777619273972, 11.842719282327, 39.1066916694999, > 32.0936130717624, 66.8755062286136, 53.7796429887741, > 17.6918060129541, > 11.5902257671425, 34.6482322781408, 9.89949493661167, > 26.1629509039023, > NA, NA), Glucose.se = c(3.71162415205983, 15.9304041937980, NA, > 4.96272496248326, NA, 3.47835210025284, 4.12383029856479, > 2.40188814616057, > 5.61456439390745, 3.47781642709786, 2.11217938990701, > 2.55556908208981, > 2.29523142628873, 3.06500013246251, 2.50541382409208, > 2.23038958057991, > 2.04858155574352, 2.57576322922309, 1.64389780704276, > 3.99112348426689, > 3.45319507311964, 2.14354680364304, 3.94067380331773, > 6.50035756909396, > 6.50222358617618, 5.32788547515463, 9.0277350426339, NA, NA, > 9.86998817966195, NA, 11.1579568022107, 14.2558467537592, > 10.8819422286036, > 6.14240723712346, 6.04669331122391, 7.78888096369861, > 5.92135964116351, > 22.5782589625015, 16.0468065358812, 33.4377531143068, > 26.8898214943871, > 10.2143689640297, 6.69161996662824, 24.5, 7, 18.5, NA, NA)), .Names > c("Group", > "Event_name", "Glucose.n", "Glucose.m", "Glucose.sd", "Glucose.se" > ), row.names = c(9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, > 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, > 31L, 32L, 33L, 34L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, > 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, > 63L), class = "data.frame") > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.David Winsemius, MD Alameda, CA, USA