Skip to content

convert table

2 messages · Richard Cotton, Peter Dalgaard

#
#This uses the reshape package
df = data.frame(coor = paste("x", 1:4, sep=""), v1=c(12,1,12,33), 
v2=c(33,123,NA,1), v3=c(1,NA,NA,NA))
mdf = melt(df)
with(mdf, table(coor, value))

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}
#
Richard.Cotton at hsl.gov.uk wrote:
Plain reshape() too:
+ v2=c(33,123,NA,1), v3=c(123,NA,NA,NA))
v
coor 1 12 33 123
  x1 0  1  1   1
  x2 1  0  0   1
  x3 0  1  0   0
  x4 1  0  1   0

(actually, varying=-1 also works.)