Hi all, Please consider the following: DataSet1.. <- data.frame(Bldgtype=c("SFDM","SFDM","SFDM","SFDM","SFDM","SFDM","APT"), Taz=c("254","254","254","564","564","564","564"),stringsAsFactors = FALSE) PeriodResType_Zx <- tapply(as.character(DataSet1..$Bldgtype), as.character(DataSet1..$Taz), table) PeriodResType_Zx $`254` SFDM 3 $`564` APT SFDM 1 3 DataSet2.. <- data.frame(Bldgtype=c("SFDM","SFDM","SFDM","SFDM","SFDM","SFDM"), Taz=c("254","245","564","564","564","564")) PeriodResType_Zx <- tapply(DataSet2..$Bldgtype, DataSet2..$Taz, table) PeriodResType_Zx Data set 1 returns the desired outcome, an array with elements consisting of a labeled table Data set 2 returns an array without the table labeled. This is occuring becuase there are not a variety of Bldgtypes in data set two, but this is a reality of the data so how can i get the data into the same format, with a Bldgtype descriptor in the array like the Data set 1 result? Thanks all Cheers -- View this message in context: http://r.789695.n4.nabble.com/More-issues-with-apply-tp4293529p4293529.html Sent from the R help mailing list archive at Nabble.com.
On Jan 13, 2012, at 4:55 PM, LCOG1 wrote:> Hi all, > Please consider the following: > > DataSet1.. <- > data > .frame(Bldgtype=c("SFDM","SFDM","SFDM","SFDM","SFDM","SFDM","APT"), > Taz=c("254","254","254","564","564","564","564"),stringsAsFactors = > FALSE) > PeriodResType_Zx <- tapply(as.character(DataSet1..$Bldgtype), > as.character(DataSet1..$Taz), table) > PeriodResType_Zx > > $`254` > > SFDM > 3 > > $`564` > > APT SFDM > 1 3 > > DataSet2.. <- > data.frame(Bldgtype=c("SFDM","SFDM","SFDM","SFDM","SFDM","SFDM"), > Taz=c("254","245","564","564","564","564")) > PeriodResType_Zx <- tapply(DataSet2..$Bldgtype, DataSet2..$Taz, table) > PeriodResType_Zx > > Data set 1 returns the desired outcome, an array with elements > consisting of > a labeled table > > Data set 2 returns an array without the table labeled. > > This is occuring becuase there are not a variety of Bldgtypes in > data set > two, but this is a reality of the data so how can i get the data > into the > same format, with a Bldgtype descriptor in the array like the Data > set 1 > result?You do not actually say what sort of output you want (other than by analogybut try using this as the first column in your data.frame call: Bldgtype =factor(c("SFDM","SFDM","SFDM","SFDM","SFDM","SFDM") ,levels=c("SFDM", "APT")) -- David Winsemius, MD West Hartford, CT
Sorry I wasn't completely clear, I am not 100% sure I know all the terminology but what I want the array to store is both 'Taz' with the 'Bldgtype' count designations like the result from data set one returns. When there isn't more than one type of 'Bldgtype' like in data set 2 the 'Bldgtype' designation disappears in the array results. I tried changing the data type to a factor but it doesn't appear to change the results in data set two though in data set 1 it does show 0 for the missing 'Bldgtype'. Any direction on this or how to set up my data differently is appreciated. Thanks all Cheers, Josh -- View this message in context: http://r.789695.n4.nabble.com/More-issues-with-apply-tp4293529p4297794.html Sent from the R help mailing list archive at Nabble.com.