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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -