How to (idiomatically in R) create a data.frame from values with column and row indexes? -
i have data.frame l, each row contains 3 cells: 'x', 'y', 'value'. need create new data.frame values in indexes 'x' , 'y'. naive solution this:
out = data.frame() for(i in 1:nrow(l)) { row <- l[i,] out[row[['x']], row[['y']]] <- row['value'] }
is there idiomatic way, how in r?
how about:
tapply(l$value,list(l$x,l$y),mean)
another option:
out = array(na,dim=c(max(l$x),max(l$y))) out[cbind(l$x,l$y)]=l$value
Comments
Post a Comment