Hello, I wrote a request yesterday on how to select a random observation that met certain criteria. I think mostly I have it figured out, but I can't figure out how to append the observations. The output just has one observation in it.
Any help would be appreciated, thanks. Christy setwd ("C:/christy/roads/") roads=read.csv("streamland23.csv") for (i in 1:nrow (roads)){ Sitetype= roads$Sitetype[i] yr=roads$REACH_Yr[i] initRchid=roads$RchID[i] huc1=roads$HUC[i] sample.df <- function(df, n) df[sample(nrow(df), n), , drop = FALSE] selected=sample.df(roads[roads$HUC == huc1, ], 1) selectedb=selected selectedb$oldrch=initRchid write.csv(selectedb,file="outhuc3.csv",append=TRUE) } -- View this message in context: http://r.789695.n4.nabble.com/randomly-select-another-observation-with-same-grouping-factor-and-year-value-do-for-every-record-in-e-tp4647351p4647420.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.