Skip to content

Add columns of dataset

3 messages · Lisa, Phil Spector

#
Dear all,

I have a dataset that looks like 

id  var1  var2  var4  var7  var8 
1    0.0   0.1    0.3    0.9    0.0    
2    0.4   0.6    0.0    0.0    0.2    
3    0.0   0.0    0.0    0.8    0.7    

Some columns are missed, for example, here the fourth (var3), sixth(var5)
and seventh (var6) columns. I want to first determine which columns are
missed in a huge dataset and then add the missed columns with the values of
zeros that looks like

id  var1  var2   var3  var4  var5  var6  var7  var8 
1    0.0   0.1     0.0    0.3   0.0    0.0   0.9    0.0    
2    0.4   0.6     0.0    0.0   0.0    0.0   0.0    0.2    
3    0.0   0.0     0.0    0.0   0.0    0.0   0.8    0.7    

Can anybody please help how to get this done? Thanks a lot in advance

Lisa
#
Lisa -
    I think something like this will do what you want:
id var1 var2 var3 var4 var5 var6 var7 var8
1  1  0.0  0.1    0  0.3    0    0  0.9  0.0
2  2  0.4  0.6    0  0.0    0    0  0.0  0.2
3  3  0.0  0.0    0  0.0    0    0  0.8  0.7

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu
On Fri, 3 Dec 2010, Lisa wrote: