I have this data file
id <- c(1,1,1,2,2,3) name <- c("A","A","A","B","B","C") value <- c(7:12) df<- data.frame(id=id, name=name, value=value) df
This function selects a random string from it:
randomRows = function(df,n){ return(df[sample(nrow(df),n),]) }
i.e.
randomRows(df,1)
But I want to randomly select one row for "name" (or for "id", which is the same) and merge this whole row into a new table, so in this case three rows. This should loop through a 2000-bit data array. Please show me how ?!
source share