Hello list, I'm new to this list, so please forgive my ignorance. I have searched R-help for some hints into what might be my problem, but I truly have no idea where to go from here. I have an object of approximately 15,000 rows and 2 columns. There are many duplicates in the first column, all with different corresponding values in the second column. For example (2 is duplicated): 2 3.2 15 1.2 2 8.4 8 9.2 7 0.4 I used the following code to aggregate these based on the first column and get the min and max: min<-aggregate(as.numeric(humanneph[,2]), list(as.numeric(humanneph[,1])), min) max<-aggregate(as.numeric(humanneph[,2]), list(as.numeric(humanneph[,1])), max) Both worked beautifully! THEN, I accidentally overwrote the object min. Since I hadn't touched the object humanneph, I copied the above code from my saved history and re-ran it. I get the following error: Error in FUN(X[[1L]], ...) : argument "INDEX" is missing, with no default So, I went back and again, copying directly from my saved history, re-made my object humanneph, and re-ran the above code again. Still the same problem!!! So, it seems that after running this code once, suddenly aggregate does not work!!! Can anyone help me? My sessionInfo() R version 2.5.1 (2007-06-27) i386-pc-mingw32 attached base packages: [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" [7] "base" Thanks! Wyatt K. Wyatt McMahon, Ph.D. Postdoctoral Research Associate Department of Internal Medicine Texas Tech University Health Sciences Center Lubbock, TX 79430 (806)743-4072 [[alternative HTML version deleted]]
I guess it will save you some trouble to give the results of 'aggregate' some other name than 'min' or 'max', as in min.humanneph <- aggregate(as.numeric(humanneph[,2]), list(as.numeric(humanneph[,1])), min) max.humanneph <- aggregate(as.numeric(humanneph[,2]), list(as.numeric(humanneph[,1])), max) HTH, Martin On Thursday 21 February 2008 (22:47:53), Mcmahon, Kevin wrote:> I'm new to this list, so please forgive my ignorance. ?I have searched > R-help for some hints into what might be my problem, but I truly have no > idea where to go from here. > > ? > > I have an object of approximately 15,000 rows and 2 columns. ?There are > many duplicates in the first column, all with different corresponding > values in the second column. ?For example (2 is duplicated): > > 2 ? ?3.2 > > 15 ?1.2 > > 2 ? ?8.4 > > 8 ? ?9.2 > > 7 ? ?0.4 > > ? > > I used the following code to aggregate these based on the first column > and get the min and max: > > min<-aggregate(as.numeric(humanneph[,2]), > list(as.numeric(humanneph[,1])), min) > > max<-aggregate(as.numeric(humanneph[,2]), > list(as.numeric(humanneph[,1])), max) > > ? > > Both worked beautifully! > > ? > > THEN, I accidentally overwrote the object min. ?Since I hadn't touched > the object humanneph, I copied the above code from my saved history and > re-ran it. ?I get the following error: > > Error in FUN(X[[1L]], ...) : argument "INDEX" is missing, with no > default > > ? > > So, I went back and again, copying directly from my saved history, > re-made my object humanneph, and re-ran the above code again. ?Still the > same problem!!! > > ? > > So, it seems that after running this code once, suddenly aggregate does > not work!!! > > ? > > Can anyone help me? > > ?-- 10.0 times 0.1 is hardly ever 1.0 ---- Kernighan and Plauger ------------------------------------------------- Dr. Martin Elff Faculty of Social Sciences LSPWIVS (van Deth) University of Mannheim A5, 6 68131 Mannheim Germany Phone: +49-621-181-2093 Fax: +49-621-181-2099 E-Mail: elff at sowi.uni-mannheim.de Web: http://webrum.uni-mannheim.de/sowi/elff/ http://www.sowi.uni-mannheim.de/lspwivs/ -------------------------------------------------
You can use match.fun x V1 V2 1 2 3.2 2 15 1.2 3 2 8.4 4 8 9.2 5 7 0.4 min <- aggregate(x, list(x[,1]), min) min <- aggregate(x, list(x[,1]), match.fun(min)) On 21/02/2008, Mcmahon, Kevin <kwyatt.mcmahon at ttuhsc.edu> wrote:> Hello list, > > > > I'm new to this list, so please forgive my ignorance. I have searched > R-help for some hints into what might be my problem, but I truly have no > idea where to go from here. > > > > I have an object of approximately 15,000 rows and 2 columns. There are > many duplicates in the first column, all with different corresponding > values in the second column. For example (2 is duplicated): > > 2 3.2 > > 15 1.2 > > 2 8.4 > > 8 9.2 > > 7 0.4 > > > > I used the following code to aggregate these based on the first column > and get the min and max: > > min<-aggregate(as.numeric(humanneph[,2]), > list(as.numeric(humanneph[,1])), min) > > max<-aggregate(as.numeric(humanneph[,2]), > list(as.numeric(humanneph[,1])), max) > > > > Both worked beautifully! > > > > THEN, I accidentally overwrote the object min. Since I hadn't touched > the object humanneph, I copied the above code from my saved history and > re-ran it. I get the following error: > > Error in FUN(X[[1L]], ...) : argument "INDEX" is missing, with no > default > > > > So, I went back and again, copying directly from my saved history, > re-made my object humanneph, and re-ran the above code again. Still the > same problem!!! > > > > So, it seems that after running this code once, suddenly aggregate does > not work!!! > > > > Can anyone help me? > > > > My sessionInfo() > > R version 2.5.1 (2007-06-27) > > i386-pc-mingw32 > > > > attached base packages: > > [1] "stats" "graphics" "grDevices" "utils" "datasets" > "methods" > > [7] "base" > > > > Thanks! > > Wyatt > > > > K. Wyatt McMahon, Ph.D. > > Postdoctoral Research Associate > > Department of Internal Medicine > > Texas Tech University Health Sciences Center > > Lubbock, TX > > 79430 > > (806)743-4072 > > > > > [[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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O