Re: [R] loading and manipulating 10 data frames-simplified

2009-03-28 Thread Mike Lawrence
And check out plyr (http://had.co.nz/plyr/) for manipulating those 10 elements.

On Fri, Mar 27, 2009 at 9:20 AM, jim holtman jholt...@gmail.com wrote:
 Look at using a 'list' as obtained from 'lapply'

 fileNames - 'your files to be read'
 Bin_main - lapply(fileNames, function(.file){
    input - read.csv(fileNames, )
    # all your calculations; e.g.,
    acre - ...
    
    cbind(acres, parprob, ...)
 })

 Now look at the structure ('str(Bin_main)') and it should have 10 (or
 how ever many files you have) elements with the data you want.

 On Thu, Mar 26, 2009 at 5:25 PM, PDXRugger j_r...@hotmail.com wrote:

 I have to load 10 different data frames and then manipulate those 10 data
 frames but would like to do this in a more simplified code than what i am
 doing.  I have tried a couple of approaches but cannot get it to work
 correctly.

 So the initial (bulky) code is:

 #Bin 1
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin1_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin1_lookup.csv,head=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin1_Acres=Bin1_main[[1]]*43560

 #Separates TAZ data from main data
 Bin1_TAZ=Bin1_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin1_TAZvacant=Bin1_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin1Acres_sum=sum(Bin1_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin1_cumper=cumsum(Bin1_Acres/Bin1Acres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin1_parprob=abs(1-Bin1_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin1Main.data = cbind(Bin1_Acres,Bin1_parprob,Bin1_TAZ,Bin1_TAZvacant)


 #Bin 2
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin2_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin2_lookup.csv,header=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin2_Acres=Bin2_main[[1]]*43560

 #Separates TAZ data from main data
 Bin2_TAZ=Bin2_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin2_TAZvacant=Bin2_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin2Acres_sum=sum(Bin2_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin2_cumper=cumsum(Bin2_Acres/Bin2Acres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin2_parprob=abs(1-Bin2_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin2Main.data = cbind(Bin2_Acres,Bin2_parprob,Bin2_TAZ,Bin2_TAZvacant)

 #Bin 3
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin3_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin3_lookup.csv,header=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin3_Acres=Bin3_main[[1]]*43560

 #Separates TAZ data from main data
 Bin3_TAZ=Bin3_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin3_TAZvacant=Bin3_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin3Acres_sum=sum(Bin3_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin3_cumper=cumsum(Bin3_Acres/Bin3Acres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin3_parprob=abs(1-Bin3_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin3Main.data = cbind(Bin3_Acres,Bin3_parprob,Bin3_TAZ,Bin3_TAZvacant)

 #Bin 4
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin4_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin4_lookup.csv,header=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin4_Acres=Bin4_main[[1]]*43560

 #Separates TAZ data from main data
 Bin4_TAZ=Bin4_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin4_TAZvacant=Bin4_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin4Acres_sum=sum(Bin4_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin4_cumper=cumsum(Bin4_Acres/Bin4Acres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin4_parprob=abs(1-Bin4_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin4Main.data = cbind(Bin4_Acres,Bin4_parprob,Bin4_TAZ,Bin4_TAZvacant)

 #Bin 5
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin5_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin5_lookup.csv,header=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin5_Acres=Bin5_main[[1]]*43560

 #Separates TAZ data 

[R] loading and manipulating 10 data frames-simplified

2009-03-27 Thread PDXRugger

I have to load 10 different data frames and then manipulate those 10 data
frames but would like to do this in a more simplified code than what i am
doing.  I have tried a couple of approaches but cannot get it to work
correctly.  

So the initial (bulky) code is:

#Bin 1
#--- 

#Loads bin data frame from csv files with acres and TAZ data
Bin1_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin1_lookup.csv,head=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin1_Acres=Bin1_main[[1]]*43560

#Separates TAZ data from main data 
Bin1_TAZ=Bin1_main[[2]]

#Separates TAZ data from main data and converts acres to square feet
Bin1_TAZvacant=Bin1_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin1Acres_sum=sum(Bin1_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin1_cumper=cumsum(Bin1_Acres/Bin1Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin1_parprob=abs(1-Bin1_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin1Main.data = cbind(Bin1_Acres,Bin1_parprob,Bin1_TAZ,Bin1_TAZvacant)


#Bin 2
#--- 

#Loads bin data frame from csv files with acres and TAZ data
Bin2_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin2_lookup.csv,header=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin2_Acres=Bin2_main[[1]]*43560

#Separates TAZ data from main data 
Bin2_TAZ=Bin2_main[[2]]

#Separates TAZ data from main data and converts acres to square feet
Bin2_TAZvacant=Bin2_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin2Acres_sum=sum(Bin2_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin2_cumper=cumsum(Bin2_Acres/Bin2Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin2_parprob=abs(1-Bin2_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin2Main.data = cbind(Bin2_Acres,Bin2_parprob,Bin2_TAZ,Bin2_TAZvacant)

#Bin 3 
#--- 

#Loads bin data frame from csv files with acres and TAZ data
Bin3_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin3_lookup.csv,header=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin3_Acres=Bin3_main[[1]]*43560

#Separates TAZ data from main data 
Bin3_TAZ=Bin3_main[[2]]

#Separates TAZ data from main data and converts acres to square feet
Bin3_TAZvacant=Bin3_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin3Acres_sum=sum(Bin3_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin3_cumper=cumsum(Bin3_Acres/Bin3Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin3_parprob=abs(1-Bin3_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin3Main.data = cbind(Bin3_Acres,Bin3_parprob,Bin3_TAZ,Bin3_TAZvacant)

#Bin 4
#--- 

#Loads bin data frame from csv files with acres and TAZ data
Bin4_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin4_lookup.csv,header=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin4_Acres=Bin4_main[[1]]*43560

#Separates TAZ data from main data 
Bin4_TAZ=Bin4_main[[2]]

#Separates TAZ data from main data and converts acres to square feet
Bin4_TAZvacant=Bin4_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin4Acres_sum=sum(Bin4_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin4_cumper=cumsum(Bin4_Acres/Bin4Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin4_parprob=abs(1-Bin4_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin4Main.data = cbind(Bin4_Acres,Bin4_parprob,Bin4_TAZ,Bin4_TAZvacant)

#Bin 5
#--- 

#Loads bin data frame from csv files with acres and TAZ data
Bin5_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin5_lookup.csv,header=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin5_Acres=Bin5_main[[1]]*43560

#Separates TAZ data from main data 
Bin5_TAZ=Bin5_main[[2]]

#Separates TAZ data from main data and converts acres to square feet
Bin5_TAZvacant=Bin5_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin5Acres_sum=sum(Bin5_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin5_cumper=cumsum(Bin5_Acres/Bin5Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin5_parprob=abs(1-Bin5_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin5Main.data = cbind(Bin5_Acres,Bin5_parprob,Bin5_TAZ,Bin5_TAZvacant)

#Bin 6
#--- 

#Loads bin data frame from csv files with acres and TAZ data
Bin6_main -

Re: [R] loading and manipulating 10 data frames-simplified

2009-03-27 Thread Uwe Ligges
Put the data.frames as elements in a list and loop / sapply() over that 
list.


Uwe Ligges


PDXRugger wrote:

I have to load 10 different data frames and then manipulate those 10 data
frames but would like to do this in a more simplified code than what i am
doing.  I have tried a couple of approaches but cannot get it to work
correctly.  


So the initial (bulky) code is:

#Bin 1
#--- 


#Loads bin data frame from csv files with acres and TAZ data
Bin1_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin1_lookup.csv,head=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin1_Acres=Bin1_main[[1]]*43560

#Separates TAZ data from main data 
Bin1_TAZ=Bin1_main[[2]]


#Separates TAZ data from main data and converts acres to square feet
Bin1_TAZvacant=Bin1_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin1Acres_sum=sum(Bin1_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin1_cumper=cumsum(Bin1_Acres/Bin1Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin1_parprob=abs(1-Bin1_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin1Main.data = cbind(Bin1_Acres,Bin1_parprob,Bin1_TAZ,Bin1_TAZvacant)


#Bin 2
#--- 


#Loads bin data frame from csv files with acres and TAZ data
Bin2_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin2_lookup.csv,header=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin2_Acres=Bin2_main[[1]]*43560

#Separates TAZ data from main data 
Bin2_TAZ=Bin2_main[[2]]


#Separates TAZ data from main data and converts acres to square feet
Bin2_TAZvacant=Bin2_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin2Acres_sum=sum(Bin2_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin2_cumper=cumsum(Bin2_Acres/Bin2Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin2_parprob=abs(1-Bin2_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin2Main.data = cbind(Bin2_Acres,Bin2_parprob,Bin2_TAZ,Bin2_TAZvacant)

#Bin 3 
#--- 


#Loads bin data frame from csv files with acres and TAZ data
Bin3_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin3_lookup.csv,header=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin3_Acres=Bin3_main[[1]]*43560

#Separates TAZ data from main data 
Bin3_TAZ=Bin3_main[[2]]


#Separates TAZ data from main data and converts acres to square feet
Bin3_TAZvacant=Bin3_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin3Acres_sum=sum(Bin3_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin3_cumper=cumsum(Bin3_Acres/Bin3Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin3_parprob=abs(1-Bin3_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin3Main.data = cbind(Bin3_Acres,Bin3_parprob,Bin3_TAZ,Bin3_TAZvacant)

#Bin 4
#--- 


#Loads bin data frame from csv files with acres and TAZ data
Bin4_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin4_lookup.csv,header=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin4_Acres=Bin4_main[[1]]*43560

#Separates TAZ data from main data 
Bin4_TAZ=Bin4_main[[2]]


#Separates TAZ data from main data and converts acres to square feet
Bin4_TAZvacant=Bin4_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin4Acres_sum=sum(Bin4_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin4_cumper=cumsum(Bin4_Acres/Bin4Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin4_parprob=abs(1-Bin4_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin4Main.data = cbind(Bin4_Acres,Bin4_parprob,Bin4_TAZ,Bin4_TAZvacant)

#Bin 5
#--- 


#Loads bin data frame from csv files with acres and TAZ data
Bin5_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin5_lookup.csv,header=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin5_Acres=Bin5_main[[1]]*43560

#Separates TAZ data from main data 
Bin5_TAZ=Bin5_main[[2]]


#Separates TAZ data from main data and converts acres to square feet
Bin5_TAZvacant=Bin5_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin5Acres_sum=sum(Bin5_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin5_cumper=cumsum(Bin5_Acres/Bin5Acres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin5_parprob=abs(1-Bin5_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin5Main.data = cbind(Bin5_Acres,Bin5_parprob,Bin5_TAZ,Bin5_TAZvacant)

#Bin 6
#--- 

Re: [R] loading and manipulating 10 data frames-simplified

2009-03-27 Thread jim holtman
Look at using a 'list' as obtained from 'lapply'

fileNames - 'your files to be read'
Bin_main - lapply(fileNames, function(.file){
input - read.csv(fileNames, )
# all your calculations; e.g.,
acre - ...

cbind(acres, parprob, ...)
})

Now look at the structure ('str(Bin_main)') and it should have 10 (or
how ever many files you have) elements with the data you want.

On Thu, Mar 26, 2009 at 5:25 PM, PDXRugger j_r...@hotmail.com wrote:

 I have to load 10 different data frames and then manipulate those 10 data
 frames but would like to do this in a more simplified code than what i am
 doing.  I have tried a couple of approaches but cannot get it to work
 correctly.

 So the initial (bulky) code is:

 #Bin 1
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin1_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin1_lookup.csv,head=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin1_Acres=Bin1_main[[1]]*43560

 #Separates TAZ data from main data
 Bin1_TAZ=Bin1_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin1_TAZvacant=Bin1_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin1Acres_sum=sum(Bin1_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin1_cumper=cumsum(Bin1_Acres/Bin1Acres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin1_parprob=abs(1-Bin1_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin1Main.data = cbind(Bin1_Acres,Bin1_parprob,Bin1_TAZ,Bin1_TAZvacant)


 #Bin 2
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin2_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin2_lookup.csv,header=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin2_Acres=Bin2_main[[1]]*43560

 #Separates TAZ data from main data
 Bin2_TAZ=Bin2_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin2_TAZvacant=Bin2_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin2Acres_sum=sum(Bin2_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin2_cumper=cumsum(Bin2_Acres/Bin2Acres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin2_parprob=abs(1-Bin2_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin2Main.data = cbind(Bin2_Acres,Bin2_parprob,Bin2_TAZ,Bin2_TAZvacant)

 #Bin 3
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin3_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin3_lookup.csv,header=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin3_Acres=Bin3_main[[1]]*43560

 #Separates TAZ data from main data
 Bin3_TAZ=Bin3_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin3_TAZvacant=Bin3_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin3Acres_sum=sum(Bin3_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin3_cumper=cumsum(Bin3_Acres/Bin3Acres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin3_parprob=abs(1-Bin3_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin3Main.data = cbind(Bin3_Acres,Bin3_parprob,Bin3_TAZ,Bin3_TAZvacant)

 #Bin 4
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin4_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin4_lookup.csv,header=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin4_Acres=Bin4_main[[1]]*43560

 #Separates TAZ data from main data
 Bin4_TAZ=Bin4_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin4_TAZvacant=Bin4_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin4Acres_sum=sum(Bin4_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin4_cumper=cumsum(Bin4_Acres/Bin4Acres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin4_parprob=abs(1-Bin4_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin4Main.data = cbind(Bin4_Acres,Bin4_parprob,Bin4_TAZ,Bin4_TAZvacant)

 #Bin 5
 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin5_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin5_lookup.csv,header=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin5_Acres=Bin5_main[[1]]*43560

 #Separates TAZ data from main data
 Bin5_TAZ=Bin5_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin5_TAZvacant=Bin5_main[[3]]*43560

 #Sums