[R] help appending randomly selected observation based on criteria

csmeredith csmeredith at fs.fed.us
Thu Oct 25 16:53:43 CEST 2012


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.




More information about the R-help mailing list