[R] Coerce rownames to factor for ordering

2012-11-29 Thread LCOG1
Hi all, 
   I think this might be an easy one but I cannot think of a way to do this
other than what I am currently attempting.  I simply want to sort my data
frame's rownames by a defined vector so that the plots I generate from that
vector are in the desired order 

Consider the test data below:

#Create test data   
DataToPlot.. - data.frame(Location1 = c(100,200),Location2 =
c(200,400))
#Name rowns
rownames(DataToPlot..) - c(Fall,Summer)
#Attempt to coerce row names to factors 
rownames(DataToPlot..) - as.factor(rownames(DataToPlot..))
#Attenmpt to sort rownames by defined vector
rownames(DataToPlot..)- reorder(as.factor(rownames(DataToPlot..)),
new.order = c(Summer,Fall,Winter,Spring))

The rownames do not reorder nor do they remain factors.  

Perhaps I can just sort these in the plot?  Not sure whats easier/possible?

barchart(DataToPlot..SeCl , horizontal = FALSE, ylab = Average Weekday
Counts,
group = colnames(DataToPlot..SeCl ), col =
Colors.[rownames(DataToPlot..SeCl)] )


Thanks for any help.

Josh



--
View this message in context: 
http://r.789695.n4.nabble.com/Coerce-rownames-to-factor-for-ordering-tp4651330.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Sorting a data frame by specifying a vector

2012-10-11 Thread LCOG1
Hello all, 
   I cannot seem to figure out this seemingly simple procedure.  

I want to sort a data frame by a specified character vector.

So for :

df.. - data.frame(Season=rep(c(Summer,Fall,Winter,Spring),4),Obs=
runif(length(rep(c(Summer,Fall,Winter,Spring),4

I want to sort the data frame by the seasons but in the order I specify
since alphapetically would not put the season in sequential order

I tried the following and a few other things but no dice.  It looks like I
will have to convert to factors.  Any thoughts?  Thanks

df.. -
df..[sort(as.factor(Df..$Season,levels=c(Summer,Fall,Winter,Spring))),]

Josh



--
View this message in context: 
http://r.789695.n4.nabble.com/Sorting-a-data-frame-by-specifying-a-vector-tp4645867.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] add leading zeros

2012-07-26 Thread LCOG1
Hi all, 
 Trying to use an apply to add leading zeros to a set of values in a
given vector.  I only want to add enough zeros so that the total number of
characters is 5, so if I have an element 1 i want 1 or 9000 I want
09000.  I tried 

vec - 1:1000
sapply(vec, FUN = sprintf(paste(%0,(5-nchar(x)),d,sep=),x)) 

but she doesnt work.  I struggle with the apply family for sure.  Thanks

Josh 



--
View this message in context: 
http://r.789695.n4.nabble.com/add-leading-zeros-tp4638031.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] lattice histogram log and non log values

2012-06-27 Thread LCOG1
Hello all, 
  Please consider the following

library(lattice)
Colors. -rep(brewer.pal(7, Dark2),2)
color - 1

Data.X.. - data.frame(UnitArea = c(rnorm(1000), rnorm(1000)), Type =
c(rep(Base,1000),rep(Log,1000)))

histogram( ~ UnitArea |  Type, data = Data.X..,
  xlab = Unit Area, type = density,
  panel = function(x, ... ){
  panel.histogram(x, ...)
  panel.mathdensity(dmath = dnorm, col = black,
args = list(mean=mean(x),sd=sd(x)))
  }, col = Colors.[color], layout = c(1, 2),
   scales=list(log = c(F,T),tick.number=list(8), rot = c(0, 90),
 x = list(relation = 'free')))

I want to plot on the same page distributions both observed values and the
logged values.  I tried using the log parameter e.g. log = c(F,T) but I dont
think this is right.When I tried transforming the data before plotting
the scales were all messed up. Guidance would be appreciated.  Thanks

Also, is there a way to simply plot multiple panels like the base graphics
package using  par(new = TRUE) in the following?  It just replaces the first
plot so maybe I shouldn't be trying to use the lattice package with the base
graphics package. 

#Set plot paramerters
par(mfrow=c(3,2), oma=c(3,3,3,3))

#Base
Data.X - rnorm(100)
histogram( ~ Data.X,
  xlab = Unit Area (Log Transformed), type = density,
  panel = function(x, ...) {
  panel.histogram(x, ...)
  panel.mathdensity(dmath = dnorm, col = black,
args = list(mean=mean(x),sd=sd(x)))
  }, col = Colors.[color], layout = c(1, 2))

   par(new = T)
#Transform
Data.X - log( rnorm(1000))
histogram( ~ Data.X,
  xlab = Unit Area (Log Transformed), type = density,
  panel = function(x, ...) {
  panel.histogram(x, ...)
  panel.mathdensity(dmath = dnorm, col = black,
args = list(mean=mean(x),sd=sd(x)))
  }, col = Colors.[color], layout = c(1, 2))

--
View this message in context: 
http://r.789695.n4.nabble.com/lattice-histogram-log-and-non-log-values-tp4634667.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Using object as literal value in list vector

2012-06-20 Thread LCOG1
Hello all , 
  This is a pretty simple question I think but cannot find an answer on the
list or in my brain.  I would like to iterate through a loop and use a
vector of strings to name a number of list elements.  For instance 

   #Create vector of strings
Et- c(ACC,RTL,WHL)
MeanValues_ - list(ACC = 1000, RTL = 2000, WHL = 3000)

#Iterate through each element of vector
NewMeans_ - list()
for(et in Et){
NewMeans_ - c(NewMeans_,list(et = unlist(MeanValues_[et]) * 
.80 ))
}

Returns
 NewMeans_ 
$et
ACC 
800 

$et
 RTL 
1600 

$et
 WHL 
2400 

But I want 'et' to be the object value of et, so it would be $ACC, $RTL, and
$WHL.  I realize there may be another way to actually do what I want to do
as far as applying the calculation but I have a bunch of code structured
around the need for my list coming in a certain way.  Thanks

Josh

--
View this message in context: 
http://r.789695.n4.nabble.com/Using-object-as-literal-value-in-list-vector-tp4633912.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Probably a good use for apply

2012-05-31 Thread LCOG1
This is great thank you.  I think I am getting the hang of some of the apply
functions.  I am stuck again however.  I have list test_ below and would
like to apply the sample function using each element of each vector as the
probability and return a TRUE or FALSE that I will ultimately sum the TRUES
by vector.

test_- list(a=c(.85,.10),b=c(.99,.05))
#Write a function to sample based on labor force participation rates to
determine presence of workers in household
sampleWorker - function(x) return(sample(c(TRUE,FALSE),x, replace = TRUE,
prob = c(x, 1-x)))
IsWorker.Hh_ - lapply(test , sampleWorker)

I am doing something wrong with the setup becuase i am getting an error
about specifying probabilities incorrectly.

The result I am looking for for  IsWorker_ to be (assuming the .85, and . 99
probabilities 'win' from each vector and the lower values do not. 

 IsWorker_
$a
[1]TRUE
$b
[1]TRUE

but ultimately I will need to sum the TRUEs for each vector 

 IsWorker_
$a
[1] 1
$b
[1] 1

   
Thanks 

Josh

--
View this message in context: 
http://r.789695.n4.nabble.com/Probably-a-good-use-for-apply-tp4631883p4631974.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Probably a good use for apply

2012-05-30 Thread LCOG1
Hi all, 
  I Have a data frame test.. that I would like to convert into a list below
test_ but am unsure how to efficiently do this.  I can do it in a for loop
but my data set is huge and it takes forever.  Wondering how I can do this
more efficiently.  So again how to I go from test.. to test_ below?  
#Data frame
test.. - data.frame(Apples = c(1,3,0,0,1), Pears = c(0,0,1,0,2), Beans =
c(1,2,1,0,0))

#list - my desired outcome
test_ - list(1 = c(Apples,Beans),
  2 = c(Apples,Apples,Apples,Beans,Beans),
  3 = c(Pears,Beans),
  4 = c(NULL),
  5 = c(Apples,Pears,Pears))

Thanks

Josh

--
View this message in context: 
http://r.789695.n4.nabble.com/Probably-a-good-use-for-apply-tp4631883.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] I bet apply has a solution

2012-02-06 Thread LCOG1
Hi all 
For the data below, I would like to return a logical value indicating
differences in the data.

#Create data
Data..-data.frame(a=rep(1,10),b=c(rep(1,9),2),c=c(rep(1,8),2,2))

   a b c
1  1 1 1
2  1 1 1
3  1 1 1
4  1 1 1
5  1 1 1
6  1 1 1
7  1 1 1
8  1 1 1
9  1 1 2
10 1 2 2


So what I want is to return logical value telling me if all the values are
the same.  So the result would be a b c DidChange
1  1 1 1 FALSE
2  1 1 1 FALSE
3  1 1 1 FALSE
4  1 1 1 FALSE
5  1 1 1 FALSE
6  1 1 1 FALSE
7  1 1 1 FALSE
8  1 1 1 FALSE
9  1 1 2  TRUE
10 1 2 2  TRUE

I bet apply could handle this elegantly but that family of functions is
still not 100% intuitive to me.  Thoughts.  Thanks everyone

Cheers, 
 Josh


--
View this message in context: 
http://r.789695.n4.nabble.com/I-bet-apply-has-a-solution-tp4362294p4362294.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] More issues with apply

2012-01-15 Thread LCOG1
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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] More issues with apply

2012-01-13 Thread LCOG1
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 
   13 

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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] To Try or to TryCatch, I have tried to long

2011-12-06 Thread LCOG1
So after about 4 hours struggling with Try and TryCatch I am throwing in the
towel.  I have a more complicated function that used logspline through
iterative distributions and at some point the logspline doesnt function
correctly for some subsets but is fine with others so I need to be able to
identify when the error occurs and stop curtailing the distribution and I
think this Try or TryCatch should do the trick but I think I am missing
something here. A simple example


result_-list()
for(i in 1:10){
  if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
#If sqrt fails
result_[[i]]-0 } else {
#If sqrt succeeds
result_[[i]] - 1 }
}


I would expect this to fail only when i  9 but succeeds  each time.  DO i
need to specify something different where try-error resides?  Thanks guys

Cheers, 
 Josh


--
View this message in context: 
http://r.789695.n4.nabble.com/To-Try-or-to-TryCatch-I-have-tried-to-long-tp4165578p4165578.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Summarizing elements of a list

2011-12-02 Thread LCOG1
Thank you for the help, I knew it could be done with a member of the apply 
family.  I struggle with apply stuff though, its not always intuitive for me 
with these functions.

Cheers,
 JR

From: Sarah Goslee [via R] [mailto:ml-node+s789695n414453...@n4.nabble.com]
Sent: Thursday, December 01, 2011 6:44 PM
To: ROLL Josh F
Subject: Re: Summarizing elements of a list

How about:

lapply(Version1_, subset, subset=c(TRUE, FALSE))
or sapply() depending on what you want the result to look like.

Thanks for the reproducible example.

Sarah

On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 [hidden 
email]/user/SendEmail.jtp?type=nodenode=4144538i=0 wrote:

 Hi everyone,
   I looked around the list for a while but couldn't find a solution to my
 problem.  I am storing some results to a simulation in a list and for each
 element i have two separate vectors(is that what they are called, correct my
 vocab if necessary). See below

 Version1_-list()
 for(i in 1:5){
Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1))
 }

 What I want is to put all of the elements' 'First' vectors into a single
 list to box plot. But whats a more elegant solution to the below?

 c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First)

 since i have 50 or more simulations this is impractical and sloppy.  Do I
 need to store my data differently or is their a solution on the back end?
 Thanks all.

 Josh

--
Sarah Goslee
http://www.functionaldiversity.org

__
[hidden email]/user/SendEmail.jtp?type=nodenode=4144538i=1 mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4144538.html
To unsubscribe from Summarizing elements of a list, click 
herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4142479code=anJvbGxAbGNvZy5vcmd8NDE0MjQ3OXwtMTcwMzUwNjI0Mg==.
NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml


--
View this message in context: 
http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4148568.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Summarizing elements of a list

2011-12-02 Thread LCOG1
Great, this worked the fastest of all the suggestions.  Cheers,

Josh


From: Michael Weylandt [via R] [mailto:ml-node+s789695n414494...@n4.nabble.com]
Sent: Thursday, December 01, 2011 8:11 PM
To: ROLL Josh F
Subject: Re: Summarizing elements of a list

Similarly, this might work:

unlist(lapply(Version1_, `[`,First))

Michael

On Thu, Dec 1, 2011 at 9:41 PM, Sarah Goslee [hidden 
email]/user/SendEmail.jtp?type=nodenode=4144941i=0 wrote:

 How about:

 lapply(Version1_, subset, subset=c(TRUE, FALSE))
 or sapply() depending on what you want the result to look like.

 Thanks for the reproducible example.

 Sarah

 On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 [hidden 
 email]/user/SendEmail.jtp?type=nodenode=4144941i=1 wrote:
 Hi everyone,
   I looked around the list for a while but couldn't find a solution to my
 problem.  I am storing some results to a simulation in a list and for each
 element i have two separate vectors(is that what they are called, correct my
 vocab if necessary). See below

 Version1_-list()
 for(i in 1:5){
Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1))
 }

 What I want is to put all of the elements' 'First' vectors into a single
 list to box plot. But whats a more elegant solution to the below?

 c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First)

 since i have 50 or more simulations this is impractical and sloppy.  Do I
 need to store my data differently or is their a solution on the back end?
 Thanks all.

 Josh

 --
 Sarah Goslee
 http://www.functionaldiversity.org

 __
 [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=2 mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
[hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=3 mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4144941.html
To unsubscribe from Summarizing elements of a list, click 
herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4142479code=anJvbGxAbGNvZy5vcmd8NDE0MjQ3OXwtMTcwMzUwNjI0Mg==.
NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml


--
View this message in context: 
http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4148571.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Summarizing elements of a list

2011-12-01 Thread LCOG1
Hi everyone, 
   I looked around the list for a while but couldn't find a solution to my
problem.  I am storing some results to a simulation in a list and for each
element i have two separate vectors(is that what they are called, correct my
vocab if necessary). See below

Version1_-list()
for(i in 1:5){
Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1))
}

What I want is to put all of the elements' 'First' vectors into a single
list to box plot. But whats a more elegant solution to the below?

c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First)

since i have 50 or more simulations this is impractical and sloppy.  Do I
need to store my data differently or is their a solution on the back end? 
Thanks all.  

Josh

--
View this message in context: 
http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4142479.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Oh apply functions, how you confuse me

2011-09-01 Thread LCOG1
Hi guys, 
I have a crap load of data to parse and have enjoyed creating a script that
takes this data and creates a number of useful graphics for our area.  I am
unable to figure out one summary though and its all cause I dont fully
understand the apply family of functions.  Consider the following:



#Create data 
Df..-rbind(data.frame(Id=1:1008,Dir=rep(c(NB,NB,SB,SB),252),Mph=runif(1008,0,65),
Volume=runif(1008,0,19),Hour=rep(00,1008),Min5Break=rep(1:12,84),Day=rep(1,1008)),
data.frame(Id=2009:2016,Dir=rep(c(NB,NB,SB,SB),252),Mph=runif(1008,0,65),
Volume=runif(1008,0,19),Hour=rep(01,1008),Min5Break=rep(1:12,84),Day=rep(2,1008)))

#Example calc
Results_-list()

#Sum Volume by 5 minute break by Day by Direction
Results_$FiveMin.Direction-tapply(Df..$Volume,list(Df..$Min5Break,Df..$Day,Df..$Hour,Df..$Dir),sum)

The data is a snap shot of what im working with and I am trying to get to
something similar to the last line where the volumes are summed.  What i
want to do is to do a weighted average for the speed by 5 minute break.  So
for all the speeds and volumes in a given hour of 5 minute break(12 per
hour), i would want to 

sum(Volumes[1:12]*Speed[1:12]) / sum(Volumes[1:12]

The output resembling the one from the above but having these weighted
values.  I am assuming the sum function in the above would be replaced by a
function doing the calculation but I am still not sure how to do this using
apply functions, so perhaps this isnt the best option.  

Hope this is clear and hope you guys(and of course ladies) can offer some
guidance. 

Cheers, 
 Josh




--
View this message in context: 
http://r.789695.n4.nabble.com/Oh-apply-functions-how-you-confuse-me-tp3784212p3784212.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Appending to list

2011-06-22 Thread LCOG1
So im here now b/c im incredibly frustrated.  Please consider the following:

#Try 1

Data_-list()
Sn-1:12
for(sn in Sn){
for(i in 1:10){
Data.X -   rnorm(100,0,10)
Data_[[paste(sn,i,sep=-)]]-Data.X
}
}

##Try 2
Data_-list()
Sn-1:12
for(sn in Sn){
for(i in 1:10){
Data.X -   rnorm(100,0,10)
Data_[[sn]][[i]]-Data.X
}
}

In Try 1 i am able to append separately each of the 120 different
combinations of element types.  But if i want to retrieve the data i have to
create a separate value by 're' pasting the two element names (sn,i)
together instead of just referencing them via subscripts [[sn]][[i]].  I
have code for some other things where this works fine and the code im
working on currently only craps out on certain data and its all the same
(between different element types) so i cant figure out what the deal is.  

Doing things the way my code is written in Try 2 i return:

$TRN[[11]]
 [1]   3488.300 384592.030  33478.449  20542.162  28967.105   9667.843 
39702.814 250780.450  55615.836  12023.944
[11]   2060.849   3001.797   9252.429  86008.546   1209.302  26470.770 
11700.330   7575.689 328187.431

$TRN[[12]]
 [1]   2645.294  70933.649  34832.911 203584.014   7040.440  49305.850 
53736.759  22394.943 223590.439  26145.437
[11]  42278.920  41736.813  40478.030


$TRN_CLUST
 [1] 0 0 0 0 0 0 0 0 0 0 0 0

Where $TRN[[n]] goes from 1-12 (only show 11,12 here) and $TRN_CLUST should
do the same but there are times when i have missing values, hence the zero,
but it doesnt store it the same (e.g $TRN_CLUST[[1]]
[1] 0

$TRN_CLUST[[2]]
[1] 0



What nuance am i missing here?  Hope my question and issue are clear. 
Thanks 

Josh

--
View this message in context: 
http://r.789695.n4.nabble.com/Appending-to-list-tp3618093p3618093.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Summarize by two or more attributes

2011-05-17 Thread LCOG1
Okay everyone heres a likely softball for someone.

Consider the following data frame:

#Create data
x-rep(c(1,15),10)
y-rnorm(20)
z-c(rep(auto,10),rep(bus,10))
a-rep(c(1,1,2,2,3,3,4,4,5,5),2)
#Create Data frame
Df-data.frame(Source=x,Rate=y,Bin=a,Type=z)


I want to create a new column the equals the sum of the Rates for each type
(1,15) by Bin.  

A related question:  I have been using R for a while now and usually
manipulate my data in data frames but i know lists are better for R so
perhaps the above should be done using lists.  Feel free to offer
suggestions coming from that angle.  

Thanks guys

JR-



--
View this message in context: 
http://r.789695.n4.nabble.com/Summarize-by-two-or-more-attributes-tp3529825p3529825.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Summarize by two or more attributes

2011-05-17 Thread LCOG1
I will hit my own ball on this one


tapply(Df$Rate,list(Df$Bin,Df$Type),sum)

--
View this message in context: 
http://r.789695.n4.nabble.com/Summarize-by-two-or-more-attributes-tp3529825p3530034.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Loading mdb

2011-03-22 Thread LCOG1
Well im thoroughly frustrated after 25 minutes of checking and rechecking my
path.  What do i not know about loading a mdb that is keeping me from
loading my data.  

i have loaded the Hmisc library and pointed it too my data using mdb.get and
continue to get the following error. 

Error in system(paste(mdb-tables -1, file), intern = TRUE) : 
  'mdb-tables' not found

Which i realize is saying that its not reading any tables within the mdb or
not able to find any mdb at all at that location.

the command i use is simply:

RawInv.data..-mdb.get('T:/Models/LandUse/GenericLandSupplyModel/Projects/2008BaseYear/EugeneUGB/Reporting/Summary.mdb')

There is definitely a mdb in that location and the path is definitely
correct.  Its an MS Access mdb with 4 tables.  When i open the said mdb i
have to hit enter at a password window but no password is required.  Could
this be hanging up R from reading it?  I have typically used dbf and csv or
txt for import formats and am not real familiar with mdb but i realize how
elementary this question is but i have spent 25 minutes now.  What am i
missing.  

Thanks

JR


   

--
View this message in context: 
http://r.789695.n4.nabble.com/Loading-mdb-tp3397075p3397075.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] rJava software

2011-03-16 Thread LCOG1
Hey everyone,
I just saw a demonstration of a model that is built entirely in R that
allows for transportation greenhouse gas related scenario testing and it
used an awesome GUI utilizing iplots, rJava and gWidgets libraries.  Very
cool stuff.  I am a somewhat seasoned R user but cannot seem to figure out
what rJava needs to run correctly.  

I have installed Java but when i load the rJava library i get the following
error

Error in utils::readRegistry(key, HLM, 2) : 
  Registry key 'Software\JavaSoft\Java Runtime Environment' not found
Error in utils::readRegistry(key, HLM, 2) : 
  Registry key 'Software\JavaSoft\Java Development Kit' not found
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: fun(...)
  error: JAVA_HOME cannot be found from the Registry
Error: package/namespace load failed for 'rJava'

Similar posts didnt seem to have the same issue and im confused as to what
my problem is.  Do i need additional Java software?  Also, does it matter
where java is installed?  Do i need to do something special to point it in
the right direction.  Thanks and i hope you can help quickly, i am very
excited to build a GUI for one of my land use models!!

JR


--
View this message in context: 
http://r.789695.n4.nabble.com/rJava-software-tp3383366p3383366.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Dont show zero values in line graph

2011-01-06 Thread LCOG1

Hey everyone, 
   Im getting better at plotting my data but cant for the life of me figure
out how to show a line graph with missing data that doesnt continue the line
down to zero then back up to the remaining values.

Consider the following
x-c(1:5,0,0,8:10)
y-1:10

plot(0,0,xlim=c(0,10), ylim=c(0,10),type=n,main=Dont show the bloody 0
values!!)
lines(x~y, col=blue, lwd=2,)

My data is missing the 6th and 7th values and they come in as NA's so i
change them to 0s but then the plot has these ugly lines that dive toward
the x axis then back up.  I would do bar plots but i need to show multiple
sets of data on the same and side by side bars doesnt do it for me.  

So i need a line graph that starts and stops where 0s or missing values
exist.  Thoughts?

JR
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Dont-show-zero-values-in-line-graph-tp3178566p3178566.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] List elements of NULL to value

2010-11-29 Thread LCOG1

Hi everyone, 
I am posting this because i know its easy and i cant for the life of me
figure out how to do it though i have tried and through a ridiculously
complex loop made it happen.  I need to convert some list elements of NULL
value to 0s so they mesh with my data frame properly.  So for 

A-list(1,NULL)

returns

[[1]]
[1] 1

[[2]]
NULL

Would instead return

[[1]]
[1] 1

[[2]]
[1] 0

The nabble posts seem to indicate dealing with NULLs can be tricky so i am
attributing my lack of success to that, mainly so i can live with myself and
asking the list such a simple question.  Sorry again guys.

JR
-- 
View this message in context: 
http://r.789695.n4.nabble.com/List-elements-of-NULL-to-value-tp3064384p3064384.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Aggregate on identical link attributes

2010-11-16 Thread LCOG1

Okay here is a solution that works in less than 60 minutes but i feel likes
its messy, if anyone has an alternative solution i would very much
appreciate your insights.  

#Create test data
TNode-c(1:20,21)
FNode-c(rev(1:20),22)
Volume-c(rep(100,20),200)
ClassCode=c(rep(Local,20),rep(Freeway,1))
#Create data frame with test data
EmmeData..-data.frame(TNode=TNode,FNode=FNode,Volume=Volume,ClassCode=ClassCode)
 
#Create vectors to establish loops
 TNodes-unique(ED..$TNode)
 FNodes-unique(ED..$FNode)
   
EmmeData..$TF-paste(EmmeData..$TNode,EmmeData..$FNode,sep=-)
EmmeData..$FT-paste(EmmeData..$FNode,EmmeData..$TNode,sep=-)
 
#Split string into 2 elements to paste back together in reverse order as a
matching ID
EmmeData..$F-unlist(lapply(strsplit(EmmeData..$FT,split=-), [, 1))
EmmeData..$T-unlist(lapply(strsplit(EmmeData..$FT,split=-), [, 2))
EmmeData..$Match-paste(EmmeData..$F,EmmeData..$T,sep=-)
z-list()
Nd-EmmeData..$TF
for(nd in Nd){
x-EmmeData..[EmmeData..$TF==nd,]
y-EmmeData..[EmmeData..$Match==x$TF,]
if(length(y$Volume)==0){
z[[nd]]-list(ID=x$TF,Volume=x$Volume,Class=x$ClassCode) 
}
if(length(y$Volume)==1){
z[[nd]]-list(ID=x$TF,Volume=x$Volume+y$Volume,Class=x$ClassCode) 
}

}
 
CalcVolumes.. - do.call('rbind', z) 


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Aggregate-on-identical-link-attributes-tp3044009p3045949.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Aggregate on identical link attributes

2010-11-15 Thread LCOG1

Hello R community, 
   I need to do some aggregation based on the test data below.  The below
code works ok, but when its applied to my real data which includes over
9,000 records the process runs for over an hour.  I know there is a more
efficient way of doing this.  I want to Sum the below data's volumes where
FNODE and TNODE match, 

i.e. FNODE=1 and TNODE =20 - Volume=100 ,
  FNODE=20 and TNODE =1 - Volume=100 

These should be aggregated toTotalVolume= 200.  
  
Also, there are some link without partner links(see record 21 in test data). 
This record should not be summed with another link since there isnt a
compliment to sum with.

Thanks in advance.
-JR


#Create test data
TNode-c(1:20,21)
FNode-c(rev(1:20),22)
Volume-c(rep(100,20),200)
ClassCode=c(rep(Local,20),rep(Freeway,1))
#Create data frame with test data
EmmeData..-data.frame(TNode=TNode,FNode=FNode,Volume=Volume,ClassCode=ClassCode)

#Create list to store results
 LinkSum_-list()
#Create vecotrs to establish loops
  TNodes-unique(EmmeData..$TNode)
  FNodes-unique(EmmeData..$FNode)

  for(tn in TNodes){
  for(fn in FNodes){
  TF-EmmeData..[EmmeData..$TNode==tn  EmmeData..$FNode==fn,]
  FT-EmmeData..[EmmeData..$TNode==fn  EmmeData..$FNode==tn,]
  if(length(TF$TNode)0){
  
LinkSum_[[tn]]-list(ID=list(c(TF$TNode,TF$FNode)),ClassCode=TF$ClassCode,TotalVolume=TF$Volume+FT$Volume)
  }
 
  }
  }

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Aggregate-on-identical-link-attributes-tp3044009p3044009.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Alter character attribute

2010-10-28 Thread LCOG1

Hi everyone

I have some records that include a date attribute for the date and time but
i need to separate the data and analyze it separately in GIS by Month and
Year, so i need to pull these attributes out and create their own attribute
field.  

So the input:
RawData2.. returns

  ID   period_end_date
1 22 9/10/2007 0:00:00
2 44  2/2/2006 0:00:00

and i need to get 
  ID   period_end_dateMonth Year
 22 9/10/2007 0:00:00   9 2007
 44  2/2/2006 0:00:0022006

The below gets me this in list form which i can then add back into the
initial data frame BUT
i have over 4.5 million records and when i run the below it ran for more
than 18 hours and only go through about 2.7 millions records when i gave up
and ended the process.  

So how can i make this more efficient and possibly add the new attributes
(month/year) to the data frame on the fly.

Thanks guys

#Create sample data
RawData2..-data.frame(ID=c(22,44),period_end_date=c(9/10/2007
0:00:00,2/2/2006 0:00:00))

#Create lists to store month and year results
Data.Month_-list()
Data.Year_-list()
#pull out year/month attribute at put in own column
for(i in 1:length(RawData2..$ID)){
 #Select Record
 Data.X-RawData..[i,]
 #Separate date into month, day, and year 
 DateSplit-strsplit(Data.X$period_end_date,/)
 #Select month
 Month-unlist(DateSplit)[1]
 #Separate year from time attribute
 Year.X-strsplit(unlist(DateSplit)[3], )
 Year.Y-unlist(Year.X)[1]
 Data.Month_[[i]]-Month
 Data.Year_[[i]]-Year.Y

}


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Alter-character-attribute-tp3018202p3018202.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Alter character attribute

2010-10-28 Thread LCOG1

Changing the filed into date format then pulling out the month/year worked
best.  Thanks, i knew it was gonna be easy.

Cheers
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Alter-character-attribute-tp3018202p3018255.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Cut including the 0 value as separate bin

2010-10-26 Thread LCOG1

Hi everyone,   

I have been using R too long to have to ask this but here i am.  How do i
create a separate bin for the 0 value?  So for:

#Create data frame
DF-data.frame(A=0:20)
#Create label vector
labs-1:6
#Create buckets and label
DF$Cut-cut(DF$A,c(0,4,8,12,14,16,20),labels=labs,include.lowest=TRUE)

I want the 0(zero) value to be in a separate bin.  

Sorry for the lame post...

Thanks guys.

JR
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Cut-including-the-0-value-as-separate-bin-tp3014503p3014503.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Transforming character vector

2010-09-13 Thread LCOG1

Hi guys, 
  Cant seem to find a solution for this.  I am looking for a substitute for
cut that can transform character vectors.  So as cut would be used below to
transform YearCat- YearCat2 base on Year and vector
Ag-c(00-'70,'71-'75,'76-'85,'86-'09) using 'cut '
FleetData$YearCat-cut(FleetData$Year,c(0,1970,1975,1985,2009),labels=Ag)

  Make Year YearCat YearCat2
1   DODG2003'86-'09 (2002,2003]
3   FORD1995'86-'09 (1994,1995]
5   JEP 1997'86-'09 (1996,1997]
6   JEP 1997'86-'09 (1996,1997]
7   DODG2002'86-'09 (2001,2002]
8   BMW 1997'86-'09 (1996,1997]
11  TOYT2006'86-'09 (2005,2006]
12  CHEV1997'86-'09 (1996,1997]
13  CHEV1992'86-'09 (1991,1992]
14  CHEV1996'86-'09 (1995,1996]

I need to do the same for a fueltype where each record has a character
representing the data instead of a numeral(as in year).  No reproducible
code or data because i think this is pretty straight forward.  I could do
this using a series of loops but i think there is prob a more elegant way. 
Use of grep?  Thanks for the help

JR

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Transforming-character-vector-tp2537881p2537881.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] proportion

2010-09-13 Thread LCOG1

Hi , 
 SO i have been on a role of asking simple questions lately.  So much for
feeling like im getting this R business.  

I wrote a script 2 weeks ago that utilized proportion to turn values in a
table (from table) into proportions to then graph.  I now get an error
that proportion is not a function so im confused.  I ran the script a few
times and im thinking maybe i had another library loaded from a previous
process and that it wasnt listed in my script and now isnt being loaded.  So
question is what library do i need to load or what other updates or changes
have been made that now R cant find proportion?

Probably useless with other code/data:
 textplot(paste(names(TrkSUV.Ag[[zp]]),proportion(TrkSUV.Ag[[zp]])),
halign=center, valign=center,cex=1)
  
-- 
View this message in context: 
http://r.789695.n4.nabble.com/proportion-tp2538185p2538185.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] readShapeSpatial error with 2.11.1

2010-09-08 Thread LCOG1

Anyone encounter an issue with using the readShapeSpatial function from
maptools in the latest version of R.  I get a simple Error in
read.dbf(filen) : unable to open DBF file but when i run the exact scrip in
2.10.0 the script produces the map just fine.  Sorry for no code but i
figured this may have been an unnecessary input.   

J
-- 
View this message in context: 
http://r.789695.n4.nabble.com/readShapeSpatial-error-with-2-11-1-tp2532089p2532089.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Plotting multiple histograms on same panel

2010-08-23 Thread LCOG1

Hey everyone, 
   So i cant figure this out.  when using histogram() from lattice instead
of hist() i get what i want as far as output.  But using histogram i can
seem to be able to figure out how to get multiple plots on the same panel.  

So  
par(mfrow=c(3,2))
for (i in 1:20) hist(rnorm(100),main=,cex.axis=.8)

gets me about what i want but i want to use histogram() cause it gives me
the format i want but the identical code does not work for histogram().  

par(mfrow=c(3,2))
for (i in 1:20) histogram(rnorm(100),main=,cex.axis=.8)

I thought this was simply set in par() but it doesn't seem to do any good. 
Thoughts. 

Thanks
JR
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plotting-multiple-histograms-on-same-panel-tp2335426p2335426.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Pie Chart in map

2010-08-09 Thread LCOG1

Hey R'rs, 
So im sick of dealing with ESRI products and am looking to stream line a
process i now use GIS to do using R.  I have made a lot of maps using R but
have not yet seen a map that puts pie charts within the map to help
represent data like the attachment. 
http://r.789695.n4.nabble.com/file/n2318816/template1.bmp 

I found Tanimura et al. work Proportional Symbol Mapping in R, but after a
discussion with one of the authors i have learned that the function is out
of date and would require a great deal of reworking.  I also found hexbinpie
on the R graphics gallery that i could incorporate.  

Before i go through the process of rewriting or out right creation of a
process to replicate my GIS results i was hoping to make sure there wasnt
something out there i could use to start or use altogether.  Or perhaps a
set of functions that already exists that i havent thought to use.  

Thanks for the insights everyone.  

JR
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Pie-Chart-in-map-tp2318816p2318816.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Plotting multiple layers(maps) on same page

2010-08-03 Thread LCOG1

Hey guys and gals,
   I searched through the forum and a bunch of R-mapping dedicated sites but
have not found what i know is quite elementary process, mapping more than
one layer on the same plot.  I need to show some reference lines for the map
to make sense.  I know the below wont work for anyone but to show what im
trying to do:

TazFile - data/input/TAZ.shp
UGBFile- data/input/metugb.shp
TazShape - readShapeSpatial(TazFile)
UGBShape - readShapeSpatial(UGBFile)

#Write out to pdf
pdf(Results/HhEmpForecast.pdf, width=8.2, height=11, onefile=TRUE)
#Households
plot(TazShape, col=colsHh[findInterval(TazShape$Hh, brksHh,
all.inside=TRUE)])
plot(UGBShape)
title(main=Households Forecast by Taz)
legend(4199277,860791.2,title=Total Households by
Taz,LegBrksHh,fill=colsHh,cex=.8)

#Employment
plot(TazShape, col=colsEmp[findInterval(TazShape$Emp, brksEmp,
all.inside=TRUE)])
title(main=Employment Forecast by Taz)
legend(4199277,860791.2,title=Total Employment by
Taz,LegBrksEmp,fill=colsEmp,cex=.8)
#Close file
dev.off()

I need Households and employment on separate maps but i need the UGB file to
be on each for reference. Doing it the above way obviously puts the
reference map (UGB) on a separate map.  So how do i plot them on the same
page.  I thought this was easy enough but im not finding a simple answer. 
Thanks for the help.  

In Solidarity, 
JR
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plotting-multiple-layers-maps-on-same-page-tp2312223p2312223.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting multiple layers(maps) on same page

2010-08-03 Thread LCOG1

I have done graphs but im trying to figure out how to map multiple shape files 
onto the same R plot and eventually export to pdf.

Does this somehow apply and im missing the transfer?


From: Wu Gong [via R] [mailto:ml-node+2312414-731348129-103...@n4.nabble.com]
Sent: Tuesday, August 03, 2010 11:48 AM
To: ROLL Josh F
Subject: Re: Plotting multiple layers(maps) on same page

Is this you want?
plot((1:20)^2,1:20,type=b,lwd=4,col=blue)
lines((1:20)^3,1:20,type=b,lwd=4,col=red)
A R learner.



View message @ 
http://r.789695.n4.nabble.com/Plotting-multiple-layers-maps-on-same-page-tp2312223p2312414.html
To unsubscribe from Plotting multiple layers(maps) on same page, click here 
(link removed) ==.


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plotting-multiple-layers-maps-on-same-page-tp2312223p2312417.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Transforming list to data frame with corresponding columns

2010-06-07 Thread LCOG1

Hi all, 
   Consider the following.


a-list(c(MHsub,MHsub,SFD,Duplex))
b-list(c(MHsub,MHsub,SFD))
c-list(c(MHpark,SFD,SFD))
d-list(c(MultiFam,MultiFam,MultiFam,Duplex))

all-list(a,b,c,d)
names(all)-c(5,6,7,8)
all2-list()
for(i in 1:length(all)){
all2[[i]]-table(unlist(all[i]))
}
names(all2)-names(all)

What i want to do is to put each of the elements of the list into a data
frame where the element represents a row and each vector is accounted for,
for all types within the entire list.  So where there isnt a particular
vector a 0 is noted so that the final product looks like this:


SFD Mhsub   Duplex  MultiFam
5   1  11   0
6   1  10   0
7   1  10   0
8   0  01   1 

Thanks for the insights.  
 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Transforming-list-to-data-frame-with-corresponding-columns-tp2246423p2246423.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transforming list to data frame with corresponding columns

2010-06-07 Thread LCOG1

Henrique,
  The last message gave me exactly what i needed.  Im still not sure whats 
going on, i will need to reference the do.call function some more.  Thanks for 
your help.


Josh Roll
Lane Council of Governments
Transportation Planner
Office: 541-682-2454
Cell: 406-671-5069
jr...@lcog.org
www.lcog.org


From: Henrique Dallazuanna [via R] 
[mailto:ml-node+2246612-389423334-103...@n4.nabble.com]
Sent: Monday, June 07, 2010 2:31 PM
To: ROLL Josh F
Subject: Re: Transforming list to data frame with corresponding columns

Try this:

`colnames-`(do.call(rbind, lapply(all2, '[', nm -
unique(unlist(sapply(all2, names), nm)

On Mon, Jun 7, 2010 at 4:20 PM, LCOG1 [hidden 
email]/user/SendEmail.jtp?type=nodenode=2246612i=0 wrote:


 Hi all,
   Consider the following.


 a-list(c(MHsub,MHsub,SFD,Duplex))
 b-list(c(MHsub,MHsub,SFD))
 c-list(c(MHpark,SFD,SFD))
 d-list(c(MultiFam,MultiFam,MultiFam,Duplex))

 all-list(a,b,c,d)
 names(all)-c(5,6,7,8)
 all2-list()
 for(i in 1:length(all)){
 all2[[i]]-table(unlist(all[i]))
 }
 names(all2)-names(all)

 What i want to do is to put each of the elements of the list into a data
 frame where the element represents a row and each vector is accounted for,
 for all types within the entire list.  So where there isnt a particular
 vector a 0 is noted so that the final product looks like this:


SFD Mhsub   Duplex  MultiFam
 5   1  11   0
 6   1  10   0
 7   1  10   0
 8   0  01   1

 Thanks for the insights.

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Transforming-list-to-data-frame-with-corresponding-columns-tp2246423p2246423.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 [hidden email]/user/SendEmail.jtp?type=nodenode=2246612i=1 mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[alternative HTML version deleted]]


__
[hidden email]/user/SendEmail.jtp?type=nodenode=2246612i=2 mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



View message @ 
http://r.789695.n4.nabble.com/Transforming-list-to-data-frame-with-corresponding-columns-tp2246423p2246612.html
To unsubscribe from Transforming list to data frame with corresponding columns, 
click here (link removed) ==.


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Transforming-list-to-data-frame-with-corresponding-columns-tp2246423p2246619.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Subsetting for unwanted values

2010-06-03 Thread LCOG1

Hi all, 
   I have toyed with this for too long today and in the past i used multiple
lines of code to get at what i want.  Consider the following:

All i need to do is subset Pc to the values that do not equal Pc.X.  The
first attempt doesnt work because i have unequal lengths.  The second
attempt doesnt give me an the right answer.  


Pc-c(Res,Com,Ind,Os,Mix,Gov,Rur)
Pc.X-c(Com,Ind,Mix)
 PcToAdd_-Pc[Pc!=Pc.X]
#Doesnt Work
AND

 PcToAdd_-subset(Pc.X,Pc.X %in% Pc)
#Works but doesnt get me what i want

I am looking a return of PcToAdd_ - Res  Os Gov Rur

This has got to be a simple answer.  Thanks  
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Subsetting-for-unwanted-values-tp2242506p2242506.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Data frame manipulation

2010-05-28 Thread LCOG1

Tal,
   Wow, i cant believe how many different manipulations i went through trying 
to coerce it into the format i wanted.  The below works nearly perfectly, i had 
to change the mean call to sum.   Im curious why you used mean?  Other than 
that thank you very much, i feel a little foolish about how long i spent trying 
to do this.  Got to love R.


From: Tal Galili [via R] 
[mailto:ml-node+2234184-1067705461-103...@n4.nabble.com]
Sent: Friday, May 28, 2010 12:04 AM
To: ROLL Josh F
Subject: Re: Data frame manipulation

Hi there,

The tool to learn for this is the cast function using the reshape package.
In your example you have more then one value for RTL, which you should think
of how to account for.
But basically, here is a solution to what you asked for (assuming I
understood you correctly)


require(reshape)
#?cast
cast(EmpTotCt.Zn..,  Taz ~ ClusterType  , value = TotEmp, mean, fill = 0)



Best,
Tal

Contact
Details:---
Contact me: [hidden email]/user/SendEmail.jtp?type=nodenode=2234184i=0 |  
972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Fri, May 28, 2010 at 3:14 AM, LCOG1 [hidden 
email]/user/SendEmail.jtp?type=nodenode=2234184i=1 wrote:


 Hello All,
 Please consider the following:

 TotEmp-c(19,6,1,1,8,44,2,33,48,1)

 ClusterType-c(AGF,CNS,OSV,RTL,RTL,TRN,REL,ACC_CLUST,RTL,WHL)
 Taz-c(0,0,0,100,100,100,101,101,102,103)


 AllCtTypes_-c(AGF,CNS,OSV,RTL,TRN,REL,ACC_CLUST,WHL,ADM_CLUST,

 HLH,HLH_CLUST,ACC,RTL_CLUST,MFG,ADM,MFG_CLUST,CNS_CLUST,PRF,PUB,
 FIN,INF_CLUST,INF,EDU_CLUST,REC,EDU,
 MNG,UTL,MIN)
 #Build data frame
 EmpTotCt.Zn..-data.frame(TotEmp,ClusterType,Taz)
 #Reverse rows to columns
 EmpTotCt.Zn2..-as.data.frame(t(as.matrix(EmpTotCt.Zn..)))


 EmpTotCt.Zn.. is a data frame that i would like to alter by adding new
 columns and input 0s where no values exist.  I tried the line below as its
 the only way i know of switching columns to rows but its far from what i am
 looking for.  So EmpTotCt.Zn.. returns

   TotEmp ClusterType Taz
 1  19 AGF   0
 2   6 CNS0
 3   1 OSV   0
 4   1 RTL 100
 5   8 RTL 100
 6  44 TRN100
 7   2 REL 101
 8  33   ACC_CLUST 101
 9  48 RTL 102
 10  1 RTL 103

 But what i want is to return the below:

AGF CNS OSV RTL RTL TRN REL ACC_CLUST
 RTL
 0   19  6   1   0   0   0   0   0
   0
 100 0   0   0   1   8   44  0   0
   0
 101 0   0   0   0   0   0   2   33
0
 102 0   0   0   0   0   0   0   0
  48
 103 0   0   0   0   0   0   0   0
1

 Where the rows represent Taz and the columns represent ALL
 ClusterType's
 found in AllCtTypes_, this would mean that the above output example would
 have many more columns with 0s in all the rows since there are no
 observations.  Its taken me a while to get the data into the above format
 and im afraid im stuck with how to get it into the final computational
 format, so hopefully someone can help.

 Perhaps i have to build a blank data frame with the appropriate dimensions
 first but i am not sure if this is the most efficient way of accomplishing
 this.

 Thanks in advance.


 --
 View this message in context:
 http://r.789695.n4.nabble.com/Data-frame-manipulation-tp2233932p2233932.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 [hidden email]/user/SendEmail.jtp?type=nodenode=2234184i=2 mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
[hidden email]/user/SendEmail.jtp?type=nodenode=2234184i=3 mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



View message @ 
http://r.789695.n4.nabble.com/Data-frame-manipulation-tp2233932p2234184.html
To unsubscribe from Data frame manipulation, click here (link removed) ==.


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Data-frame-manipulation-tp2233932p2235019.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R

[R] Data frame manipulation

2010-05-27 Thread LCOG1

Hello All, 
Please consider the following:

TotEmp-c(19,6,1,1,8,44,2,33,48,1)
ClusterType-c(AGF,CNS,OSV,RTL,RTL,TRN,REL,ACC_CLUST,RTL,WHL)
Taz-c(0,0,0,100,100,100,101,101,102,103)

AllCtTypes_-c(AGF,CNS,OSV,RTL,TRN,REL,ACC_CLUST,WHL,ADM_CLUST,
HLH,HLH_CLUST,ACC,RTL_CLUST,MFG,ADM,MFG_CLUST,CNS_CLUST,PRF,PUB,
FIN,INF_CLUST,INF,EDU_CLUST,REC,EDU,
MNG,UTL,MIN)
#Build data frame
EmpTotCt.Zn..-data.frame(TotEmp,ClusterType,Taz)
#Reverse rows to columns
EmpTotCt.Zn2..-as.data.frame(t(as.matrix(EmpTotCt.Zn..)))


EmpTotCt.Zn.. is a data frame that i would like to alter by adding new
columns and input 0s where no values exist.  I tried the line below as its
the only way i know of switching columns to rows but its far from what i am
looking for.  So EmpTotCt.Zn.. returns

   TotEmp ClusterType Taz
1  19 AGF   0
2   6 CNS0
3   1 OSV   0
4   1 RTL 100
5   8 RTL 100
6  44 TRN100
7   2 REL 101
8  33   ACC_CLUST 101
9  48 RTL 102
10  1 RTL 103

But what i want is to return the below:

AGF CNS OSV RTL RTL TRN REL ACC_CLUST   
RTL
0   19  6   1   0   0   0   0   0   
  0
100 0   0   0   1   8   44  0   0   
  0
101 0   0   0   0   0   0   2   33  
  0
102 0   0   0   0   0   0   0   0   
 48
103 0   0   0   0   0   0   0   0   
   1

Where the rows represent Taz and the columns represent ALL ClusterType's
found in AllCtTypes_, this would mean that the above output example would
have many more columns with 0s in all the rows since there are no
observations.  Its taken me a while to get the data into the above format
and im afraid im stuck with how to get it into the final computational
format, so hopefully someone can help.

Perhaps i have to build a blank data frame with the appropriate dimensions
first but i am not sure if this is the most efficient way of accomplishing
this.  

Thanks in advance.

  
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Data-frame-manipulation-tp2233932p2233932.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Automating searching text for key words

2010-04-15 Thread LCOG1

Hello all, 
Im doing some content analysis of news stories and i am looking for a
way to sort through different text lists searching for specified words then
storing the results, at this point just the count.  Heres what i have so
far:

#Load data frame of wed address to load -Creates raw word data

#Create web addresses to where text data is located
WebAdds-c(
http://anitasdailyshowpage.tripod.com/transcripts/2002bushisms.htm,http://anitasdailyshowpage.tripod.com/transcripts/2002wasntcorrspondent.htm;)
#Create text data by accessing website and putting all text from page into a
list where each element
#is represents by a word 


#Loop through and load  text from  all website addresses
WordData_-list()
for(i in 1:length(WebAdds)){
AddToUse-WebAdds[i]
Select.WebAdd-AddToUse
Select.WebAdd-as.character(Select.WebAdd)
#Remove blanks from address to it can be read
Select.WebAdd-sub([[:blank:]], , Select.WebAdd) 
WordData_[[i]]- scan(url(Select.WebAdd), what = character) 
  }
  #Define words to look for
 SearchWords_ -c(Bush,actor)

#Create lists to store retunred values WordDataResults_-list()
 AllWordDataResults_-list()
 WordDataResults_-list()

 for(i in 1:length(WordData_)){
   
for(j in 1:length(SearchWords_)){
#Loop through all transcripts searching for each of the words in the
search list
 WordData.X - sub(paste(,  SearchWords_[j], ).*, sep=),
\\1,WordData_[[i]] )
# check if no match in original string; replace with 'other'
 match - grep(SearchWords_[j], WordData.X)
WordDataResults_[[j]]-WordData.X[match]
 AllWordDataResults_[[i]]- WordDataResults_[[j]]
}

}

AllWordDataResults_

which returns 
[[1]]
character(0)

[[2]]
[1] actor.

This result basically shows that the word actor was found in the 2nd web
page searched.  It should show a Bush , with a number of
varietiest(e.g.Bush-ismsBush-ism Bushquot;,  Bushquot;. 
Bush?quot;, ,Bush Bush  AND and Actor .

So what happens above is i load to web pages in for sample content to search
through then each word is compared to each of the web pages.  Any insight in
to how to make the basic operation of above would be appreciated as well,
but this is the best i could come up with at this point.  Thanks for any
help.

Cheers, 
JR

-- 
View this message in context: 
http://n4.nabble.com/Automating-searching-text-for-key-words-tp1856444p1856444.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Getting choropleth map intervals correct

2010-03-23 Thread LCOG1

Hello all, 
Working on mapping some probabilities using R to a geographic unit called a
TAZ.The below data will work but you will have to set your directory for
the shape file.  Never did this before so hopefully this works.  ResProbs is
just supposed to be a value between 0-1, sorry if that more complicated than
it needed to be.  


TazFile - *directory*/TAZ.shp
TazShape - readShapeSpatial(TazFile)
TazShape-TazShape[order(TazShape$TAZ_NUM),]

ResTaz-25:666
ResProbs-rnorm(642,0:1)
ResProbs[ResProbs1]=.5
ResProbs[ResProbs-1]=.2
ResProbs-abs(ResProbs)

ResProbs..-data.frame(ResTaz,ResProbs)
names(ResProbs..)-c(Taz,SFsubM)
TazShape$SFsubM-ResProbs..$SFsubM[match(TazShape$TAZ_NUM,ResProbs..$Taz)]
brks-cut(TazShape$SFsubM, breaks=c(seq(0,1, by=0.1), Inf) ,
right=TRUE,include.lowest=TRUE)
cols - grey((length(brks):2)/length(brks))
plot(TazShape, col=cols[findInterval(TazShape$SFsubM, brks,
all.inside=TRUE)])

I get the error:
Error in findInterval(TazShape$SFsubM, brks, all.inside = TRUE) : 
  'vec' must be sorted non-decreasingly

The code i took this from created brks as a quantile returning:
   0%10%20%30%40%50%60% 
0. 0.03858501 0.07693546 0.11647164 0.14702968 0.18308665 0.22484961 
   70%80%90%   100% 
0.26566555 0.31217598 0.39463130 0.73439360 

which is not what i want but rather putting data into the correct bins.  I
remedied this by the above code describing brks, which now returns an
interval.  

So basically what im after is to illustrate probabilities for each of my
geographic units for my shape file with breaks at each .1, using gray or any
other color for that matter.  Thanks

  http://n4.nabble.com/file/n1679914/TAZ.shp TAZ.shp 
-- 
View this message in context: 
http://n4.nabble.com/Getting-choropleth-map-intervals-correct-tp1679914p1679914.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Setting breaks to data more appropriately

2010-03-22 Thread LCOG1

Basic question.  For the below data, i would like to but each of the values
in a bin that represents their value.  So the below would hopefully put .1
in the 0-.1 bin, .2 in the .11-.2 bin and so forth.  The outlying values
would then be put into and outer category representing everything 1.  Im
using the breaks to inform some code for making a clorepleth map that
represents probabilities, which in some cases IS greater than 1 and i need
to identify those better.  As my code stands now, my real data is put put
into this form when brks is called:

0%10%20%30%40%50%60% 
0. 0.05054675 0.07787235 0.11235238 0.14424786 0.18089360 0.21475990 
   70%80%90%   100% 
0.26309899 0.30807771 0.39478573 0.67573483.

But what i want is for the values to be placed in bins corresponding to
their value(0-.1, .11-.2, .21-.3 etc)  

Pct.SFD-c(.1,.2,.3,.4,.5,.6,.7,.8,.9,1,2,3)
brks - quantile(Pct.SFD, seq(0,1,1/10))

I think this is clear.  Thanks
-- 
View this message in context: 
http://n4.nabble.com/Setting-breaks-to-data-more-appropriately-tp1678019p1678019.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] swutching rows to columns

2010-03-22 Thread LCOG1

Hi All, 
  
Consider the following:
TRN-c(5.809657,3.1, 1.774901e-02) 
TRN_CLUST-c(-4.174682e-05,  5.538742e-05,1.2)
EmpCo-data.frame(TRN,TRN_CLUST)
row.names(EmpCo)-c(Slope,Fwy,Univ)

returns:
TRN TRN_CLUST
Slope 5.80965700 -4.174682e-05
Fwy   3.1000  5.538742e-05
Univ  0.01774901  1.20e+00

Now my own data is actually first constructed into list form(see below) so
perhaps it would be easier to perform the rows to columns operation from
that.  

List form:
$TRN
   SlopeFwy  UnivDist  
   5.80965700  3.1000   0.01774901 

What i would like to do is switch the rows to columsn so that the above now
shows:

  Slope FwyUniv
TRN   5.809657  3.1 0.01774901
TRN_CLUST -4.17E-05 5.54E-051.20E+00


Tried some things from the reshape package but i dont think thats what i
want.  I will need to do this for more variables and initial columns than
shown here so if the process is automated or easily put into an
automated(loop) form that would be best.  Gracias

JR
-- 
View this message in context: 
http://n4.nabble.com/swutching-rows-to-columns-tp1678429p1678429.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] trouble getting multinimial logit model to work properly

2010-03-10 Thread LCOG1

Greetings all, 
please consider the following data:
#Build Data frame
Slope-c(1.291370, 12.208500,  2.110930,  0.578990,  5.019520,  0.807444, 
0.554079
, 1.257080,  0.241504 , 0.184337 , 0.383044 , 0.342021)
Exposure-c(790.54,  1167.79 ,  845.58 , 1082.47 , 1189.61 ,  677.17 ,
2058.56 ,  469.09
,   112.02 ,  803.31 ,  254.14  ,1336.16)
FwyDist-c(11809.4222 ,10623.0458, 12279.6271, 11571.2744, 15400.9318, 
7786.4093,  1173.0635
 , 2630.1493 , 4408.2271  ,6333.0374  ,8070.0090,   751.3506)
RTotEmp-c( 2707.4835  , 0. ,729.5191  , 15652.1514  
,25613.8658  , 74214.9622
, 15094.1017,1682.1790 ,  15742.1817,   0.,  257715.0631  ,
13564.0576)
RTotHh-c( 38643.1731 , 17361.7998 , 96782.8727 , 57936.3218 , 42770.3231 ,
32393.5014
,40490.5267 , 32682.3341 , 17151.9293 , 35989.6510 ,167356.2668 
,63072.8678)
SFsubM-c(0,1,1,0,0,0,0,0,0,1,0,0)
TestData-data.frame(Slope,Exposure,FwyDist,RTotEmp,RTotHh,SFsubM)

#Run Model
z.out - zelig(SFsubM ~ Slope + IntDist + Exposure  + RTotEmp + RTotHh, 
 model=mlogit, data=TestData)

I get the error 
Error in attr(tt, depFactors)$depFactorVar : 
  $ operator is invalid for atomic vectors

Which i dont know what it means.  The data is a subset of my real data but
should reflect what im trying to do.  Thanks

JR
-- 
View this message in context: 
http://n4.nabble.com/trouble-getting-multinimial-logit-model-to-work-properly-tp1588079p1588079.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Removing colon from numerical data

2010-03-04 Thread LCOG1

Basic question, looked through the forum and documentation but didnt see a
solution.

So consider 

O-c(1:20)
D-c(1:,2:,3:,4:,5:,6:,7:,8:,9:,10:,11:,12:,13:,14:,15:,16:,
17:,18:,19:,20:)
Time-c(51:70)

AveTT-data.frame(O,D,Time)


I would like to remove the colon from the D column's data.  This is how
the data is being given to me and its too big to put into excel to remove
the colons.  I tried the below but neither returns what i want.  

AveTT$D-as.numeric(AveTT$D)

AveTT$D-substr(AveTT$D,1,nchar(AveTT$D)-1)

so i want 
  O   D Time
1   1  1:   51
2   2  2:   52
3   3  3:   53
4   4  4:   54
5   5  5:   55
6   6  6:   56
7   7  7:   57
8   8  8:   58
9   9  9:   59
10 10 10:   60

to become

  O   D Time
1   1  1   51
2   2  2   52
3   3  3   53
4   4  4   54
5   5  5   55
6   6  6   56
7   7  7   57
8   8  8   58
9   9  9   59
10 10 10   60

while maintaining the data's integrity.  Thanks 

JR

-- 
View this message in context: 
http://n4.nabble.com/Removing-colon-from-numerical-data-tp1578397p1578397.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] select row based on highest value

2010-02-23 Thread LCOG1

Please consider the following

#Data to use 
 Props-c(p754921,p754921 ,p754921,p75506 ,p75506
,p75506,p75506,p75508,p75508,p75508,p75508,p75508) 
 TAZ-c(38,37,37,171,171,282,171,46,46,169,169,169) 
 Area-c(109828.04,  128134.71,   46469.57, 37160.21, 
 40080.50,344679.66,16972.28, 
 342309.558, 260906.870,  17014.659,   7285.706,  10936.316) 

 TazProperties..-data.frame(Props,TAZ,Area) 


t - TazProperties.. 
v - aggregate(t$Area, by=list(t$TAZ,t$Props), sum) 
names(v) - c(TAZ, Prop, area) 
a-tapply(v$area, v$Prop, function(x) v$TAZ[which.max(x)]) 

a returns:

p754921  p75506  p75508 
 37  38  37 

and it should return

p754921  p75506  p75508 
 37  282  46

What am i doing wrong?  Thanks 
-- 
View this message in context: 
http://n4.nabble.com/select-row-based-on-highest-value-tp1566510p1566510.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] select row based on highest value

2010-02-23 Thread LCOG1

Ah perfect thank you.


From: jholtman [via R] [mailto:ml-node+1566613-1138252725-103...@n4.nabble.com]
Sent: Tuesday, February 23, 2010 2:00 PM
To: ROLL Josh F
Subject: Re: select row based on highest value

Is this better:

 sapply(split(v, v$Prop), function(x) x$TAZ[which.max(x$area)])
p754921  p75506  p75508
 37 282  46



Take a look at what you were doing.  The result of the 'tapply' is to
split v$area in to smaller groups based on v$Prop, so the 'x'
parameter is not going to be the same length as your 'v' dataframe and
therefore you are indexing to the incorrect value.  Best to split the
dataframe and then operate on the individual portions.

On Tue, Feb 23, 2010 at 3:47 PM, LCOG1 [hidden 
email]http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1566613i=0 
wrote:


 Please consider the following

 #Data to use
  Props-c(p754921,p754921 ,p754921,p75506 ,p75506
 ,p75506,p75506,p75508,p75508,p75508,p75508,p75508)
  TAZ-c(38,37,37,171,171,282,171,46,46,169,169,169)
  Area-c(109828.04,  128134.71,   46469.57, 37160.21,
  40080.50,344679.66,16972.28,
  342309.558, 260906.870,  17014.659,   7285.706,  10936.316)

  TazProperties..-data.frame(Props,TAZ,Area)


 t - TazProperties..
 v - aggregate(t$Area, by=list(t$TAZ,t$Props), sum)
 names(v) - c(TAZ, Prop, area)
 a-tapply(v$area, v$Prop, function(x) v$TAZ[which.max(x)])

 a returns:

 p754921  p75506  p75508
 37  38  37

 and it should return

 p754921  p75506  p75508
 37  282  46

 What am i doing wrong?  Thanks
 --
 View this message in context: 
 http://n4.nabble.com/select-row-based-on-highest-value-tp1566510p1566510.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 [hidden 
 email]http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1566613i=1 
 mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
[hidden 
email]http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1566613i=2 
mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



View message @ 
http://n4.nabble.com/select-row-based-on-highest-value-tp1566510p1566613.html
To unsubscribe from select row based on highest value, click here (link 
removed) ==.


-- 
View this message in context: 
http://n4.nabble.com/select-row-based-on-highest-value-tp1566510p1566657.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] matching on two criteria

2010-02-22 Thread LCOG1


Howdy y'all,

I am looking to use the match function to match a data attribute to another
data frame but i need it to do so on two criteria to ensure an appropriate
match.  The following matches incorrectly.  I know the example looks
pointless but its just an example.  Perhaps there is another way of doing
this?  Thanks

#Sample Data
Props-c(p754921,p754921 ,p754921,p75506 ,p75506 
 ,p75506,p75506 
 ,p75508,p75508,p75508,p75508,p75508) 
 TAZ-c(38,37,37,171,171,282,171,46,46,169,169,169) 
 Area-c(109828.04,  128134.71,   46469.57, 37160.21, 
 40080.50,344679.66,16972.28, 
 342309.558, 260906.870,  17014.659,   7285.706,  10936.316) 
#Creat 1st dataframe
TazProperties..-data.frame(Props,TAZ,Area)
 #Sample Data
Props2-c(p754921,p754921,p754921,p75506 ,p75506 
 ,p75506,p75506 ,p75508,p75508,p75508,p75508,p75508) 
 TAZ2-c(38,37,37,171,171,282,171,46,46,169,169,169) 
#Create 2nd data frame
TazProperties2..-data.frame(Props2,TAZ2) 

#match on prop and return area to data frame
TazProperties2..$Area-TazProperties..$Area[match(TazProperties..$Props,TazProperties..$Props)]

-- 
View this message in context: 
http://n4.nabble.com/matching-on-two-criteria-tp1565265p1565265.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Subtracting one based on an If

2010-02-18 Thread LCOG1

For the following:

 Bldgid-c(1000,1000,1000,1001,1002,1003,1003,1003)
 Maplot-c(2,20001,20002,3,30001,4,40001,40002)
 Area-c(40,170,160,50,100,100,90,110)
 #Construct Sample dataframe
 MultiLotBldgs..-data.frame(Bldgid,Maplot,Area)

CondoLots_ - tapply(MultiLotBldgs..$Maplot, MultiLotBldgs..$Bldgid, length)


CondoLots_ Returns:

1000 1001 1002 1003 
   3113 

What i want to do is to subtract 1 from the above for all cases where there
are more than one, so that  CondoLots_ returns:
1000 1001 1002 1003 
   2   112

I have tried 

for(i in 1:length(CondoLots_)){
ifelse(CondoLots_1){ 
 CondoLots2_-CondoLots_-1
}

 }
But it doesnt seem to work properly.  I think this should be simple.

Thanks in advance.
JR
-- 
View this message in context: 
http://n4.nabble.com/Subtracting-one-based-on-an-If-tp1561047p1561047.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Procedure not working for actual data

2010-02-17 Thread LCOG1

Hello all, 
   I have what i feel is a unique situation which may not be resolved with
this inquiry.  I have constructed the below data set so that i may give an
example of what im doing.  The example works perfectly and i have no issues
with it.  My problem arises with my actual data, which includes another 11
columns of data (used in later analysis) and a total of about 7000
cases(rows).  i mention the dimensions of the actual data because im
wondering if my below process would encounter problems with more data.
  To be sure the problem occurs in the last step.  Is$NotTooSmall gives me a
binary output that is then put back in MultiLotBldgs.. (as shown in the
example) to return the cases i want to keep. 
 In my actual data the binary designation is correct but when
MultiLotBldgs2.. returns it doesnt remove the cases that are False in 
Is$NotTooSmall.  Like i said my sample data works fine but my actual
implementation does not.  Any suggestions?  I know this is not easy to
answer without seeing the problem but this is the best i can do without
sending you all of my data.  

Cheers, 
JR




#Sample data
Bldgid-c(1000,1000,1001,1002,1003,1003)
Maplot-c(2,20001,3,30001,4,40001)
Area-c(40,170,50,100,100,4.9)
#Construct Sample dataframe
MultiLotBldgs..-data.frame(Bldgid,Maplot,Area)
#Get Building Areas
MultiLotBldgArea.X - unlist(tapply(MultiLotBldgs..$Area,
MultiLotBldgs..$Bldgid, 
  function(x) x))

# Calculate the proportion of the total building area in each piece of the
building
MultiLotBldgProp.X - unlist(tapply(MultiLotBldgs..$Area,
MultiLotBldgs..$Bldgid, 
  function(x) x/sum(x)))

#Identify buildings that should be considered for joining
Is$NotTooSmall.X - !(((MultiLotBldgArea.X = 45) | 
((MultiLotBldgArea.X  45)  (MultiLotBldgProp.X
 0.05

MultiLotBldgs2.. - MultiLotBldgs..[Is$NotTooSmall.X, ]

-- 
View this message in context: 
http://n4.nabble.com/Procedure-not-working-for-actual-data-tp1559492p1559492.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Selecting single TAZ based on area proportion

2010-02-08 Thread LCOG1

Good day all, 
   I am having an issue coercing my data.  Below i have some data on taxlots
and an associated TAZ(transportation analsysi zone) that each property is
within.  The main issue is that some properties cross TAZ boundaries so i
need to make a decision as to which TAZ the property belongs too, i would
like to do this based on the area of the Property and ultimately assign the
the property to the TAZ in which the majority or the most of the area is
within.  For instance in the data below:

Property  p754921  is in two TAZs, 38 and 37.  Since the property is mostly
in 37 i would like to assign this value to the list of properties(Props) so
that 

MultiTazProperties_ goes from 

$p754921
[1] 38 37 37

$p75506
[1] 171 171 282 171

$p75508
[1]  46  46 169 169 169

to

$p754921
[1]  37 

$p75506
[1] 282

$p75508
[1]  46

 PropsTAZ   Area
1  p754921  38 109828.040
2  p754921  37 128134.710
3  p754921  37  46469.570
4   p75506 171  37160.210
5   p75506 171  40080.500
6   p75506 282 344679.660
7   p75506 171  16972.280
8   p75508  46 342309.558
9   p75508  46 260906.870
10  p75508 169  17014.659
11  p75508 169   7285.706
12  p75508 169  10936.316
 


#Data to use
Props-c(p754921,p754921 ,p754921,p75506 ,p75506
,p75506,p75506
 ,p75508,p75508,p75508,p75508,p75508)
TAZ-c(38,37,37,171,171,282,171,46,46,169,169,169)
Area-c(109828.04,  128134.71,   46469.57, 37160.21, 
40080.50,344679.66,16972.28,
342309.558, 260906.870,  17014.659,   7285.706,  10936.316)

TazProperties..-data.frame(Props,TAZ,Area)

MultiTazProperties_-tapply(TAZ , Props, function(x) x)
MultiTazArea_-tapply(Area , Props, function(x) x)

Hope my inquiry is clear.  Thanks
-- 
View this message in context: 
http://n4.nabble.com/Selecting-single-TAZ-based-on-area-proportion-tp1473288p1473288.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Issue using tapply

2010-01-25 Thread LCOG1

Hello all, 
   I am trying to use the tapply function to sum some values and change the
column names of the resulting vector.  

I input 
 Emp  Et
1  10565 ACC
2   7515 ADM
3625 AGF
4   6243 CNS
5  12721 EDU
6   3924 FIN
7  18140 HLH
8   3686 INF
9  15841 MFG
10   243 MIN
11  1864 MNG
12  4664 OSV
13  5496 PRF
14  4988 PUB
15  2166 REC
16  2153 REL
17 16082 RTL
18  3582 TRN
19   757 UTL
20  5818 WHL

and i want to aggregate certain types based on the following matches

Et Em
1  AGF AFREMP
2  MIN MINEMP
3  UTL TCPEMP
4  CNS CONEMP
5  MFG MFGEMP
6  WHL WSTEMP
7  RTL RETEMP
8  TRN TCPEMP
9  INF SVCEMP
10 FIN FINEMP
11 REL FINEMP
12 PRF SVCEMP
13 MNG FINEMP
14 ADM SVCEMP
15 EDU SVCEMP
16 HLH SVCEMP
17 REC SVCEMP
18 ACC SVCEMP
19 RST SVCEMP
20 OSV SVCEMP
21 PUB GVTEMP

but the last value in my result is NA when it should be 5818. so my actual
result is 
AFREMP CONEMP FINEMP GVTEMP MFGEMP MINEMP RETEMP SVCEMP TCPEMP WSTEMP 
   625   6243 7941  498815841 2433582 81035 
6575 NA 

I have rechecks to make sure there isnt a simple labeling error but i havent
found anything.  Below is test code.

Et-c(AGF,MIN,UTL,CNS,MFG,WHL,RTL,TRN,INF,FIN,REL,
PRF,MNG,ADM,EDU,HLH,REC,ACC,RST,OSV,PUB)

Em-c(AFREMP,MINEMP,TCPEMP,CONEMP,MFGEMP,WSTEMP,RETEMP,TCPEMP,
SVCEMP,FINEMP,FINEMP,SVCEMP,FINEMP,SVCEMP,SVCEMP,SVCEMP,SVCEMP,
SVCEMP,SVCEMP,SVCEMP,GVTEMP)

EtToEm..-data.frame(Et,Em)

Emp-c(10565,7515,625,6243,12721,3924,18140,3686,15841,243,1864,4664,5496,4988
,2166,2153,16082,3582,757,5818)

Et.t-c(ACC,ADM,AGF,CNS,EDU,FIN,HLH,INF,MFG,MIN
,MNG,OSV
,PRF,PUB,REC,REL,RTL,TRN,UTL,WHL)

Emp.Et-data.frame(Emp,Et.t)
names(Emp.Et)[2]-Et

Emp.Et.Em-as.vector(Emp.Et$Em)
names(Emp.Et.Em) - Emp.Et$Et

EmpEt.Em - tapply(Emp.Et.Em[EtToEm..$Et], EtToEm..$Em, sum)

-- 
View this message in context: 
http://n4.nabble.com/Issue-using-tapply-tp1289681p1289681.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Issue using tapply

2010-01-25 Thread LCOG1

Ista you have suggested the correct solution, i didnt htink it would matter
not having that value but it did. Things work as they should now, thankyou
-- 
View this message in context: 
http://n4.nabble.com/Issue-using-tapply-tp1289681p1289764.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Create a multi dimensional array from a data frame

2010-01-21 Thread LCOG1

Hello all, 
   I have data from a csv that i need to coerce into a multi dimensional
array.  As you can see from my sample code i have yet to master building
efficient code.  I can sort of do what i want but its very cumbersome code
and i know there is a better way to do it, i am just not expereinced enought
yet.  So for the following:

#Create Data
h1i1a1-sample(1:20, 5, replace=TRUE)
h1i1a2-sample(1:20, 5, replace=TRUE)
h1i1a3-sample(1:20, 5, replace=TRUE)
h1i2a1-sample(1:20, 5, replace=TRUE)
h1i2a2-sample(1:20, 5, replace=TRUE)
h1i2a3-sample(1:20, 5, replace=TRUE)
h1i3a1-sample(1:20, 5, replace=TRUE)
h1i3a2-sample(1:20, 5, replace=TRUE)
h1i3a3-sample(1:20, 5, replace=TRUE)
h1i4a1-sample(1:20, 5, replace=TRUE)
h1i4a2-sample(1:20, 5, replace=TRUE)
h1i4a3-sample(1:20, 5, replace=TRUE)
h2i1a1-sample(1:20, 5, replace=TRUE)
h2i1a2-sample(1:20, 5, replace=TRUE)
h2i1a3-sample(1:20, 5, replace=TRUE)
h2i2a1-sample(1:20, 5, replace=TRUE)
h2i2a2-sample(1:20, 5, replace=TRUE)
h2i2a3-sample(1:20, 5, replace=TRUE)
h2i3a1-sample(1:20, 5, replace=TRUE)
h2i3a2-sample(1:20, 5, replace=TRUE)
h2i3a3-sample(1:20, 5, replace=TRUE)
h2i4a1-sample(1:20, 5, replace=TRUE)
h2i4a2-sample(1:20, 5, replace=TRUE)
h2i4a3-sample(1:20, 5, replace=TRUE)
h3i1a1-sample(1:20, 5, replace=TRUE)
h3i1a2-sample(1:20, 5, replace=TRUE)
h3i1a3-sample(1:20, 5, replace=TRUE)
h3i2a1-sample(1:20, 5, replace=TRUE)
h3i2a2-sample(1:20, 5, replace=TRUE)
h3i2a3-sample(1:20, 5, replace=TRUE)
h3i3a1-sample(1:20, 5, replace=TRUE)
h3i3a2-sample(1:20, 5, replace=TRUE)
h3i3a3-sample(1:20, 5, replace=TRUE)
#Put into data frame
hia-data.frame(h1i1a1,h1i1a2,h1i1a3,h1i2a1,h1i2a2,h1i2a3,h1i3a1,h1i3a2,h1i3a3,h1i4a1,h1i4a2,h1i4a3,h2i1a1,h2i1a2,h2i1a3,h2i2a1,h2i2a2,h2i2a3,h2i3a1,h2i3a2,h2i3a3,h2i4a1,h2i4a2,h2i4a3,h3i1a1,h3i1a2,h3i1a3,h3i2a1,h3i2a2,h3i2a3,h3i3a1,h3i3a2,h3i3a3)

i would like to produce a multidimensional array that looks something like 

  h1 h2 h3
i1X   X  X
i2X   X  X
i3X   X  X

a = 1 , TAZ = 1:5 -for all 5 TAZ values or each row

  h1 h2 h3
i1X   X  X
i2X   X  X
i3X   X  X

a = 2 , TAZ = i in 1:5 

  h1 h2 h3
i1X   X  X
i2X   X  X
i3X   X  X

a = 3 , TAZ = i in 1:5 

Basically a  matrix for all possible combination, so 27 matrices altogether. 
But i guess its more like an array of arrays?  Again i am not being lazy, i
have been working on this all day but my code, like my sample stuff is very
inefficient and ultimately not working well so im not bothering to post it. 
I know this will be complicated so thank you in advance, seeing the end code
will teach me a great deal.  Thanks

Cheers, 
JR
-- 
View this message in context: 
http://n4.nabble.com/Create-a-multi-dimensional-array-from-a-data-frame-tp1068487p1068487.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Drop last numeral

2010-01-12 Thread LCOG1

Hello all, 
  Frustrated and i know you can help 

I need to drop the last numeral of each of my values in my data set.  So for
the following i have tried the ?substring but since i have to specify the
length, but because my data are of varying lengths it doenst work so well

Data-c(1131, 1132, 1731 ,1732 ,1821 ,1822, 2221 ,,
2241 ,2242,414342 ,414371 ,414372)
Bldgid-substring(as.character(Data),1,3)

returns:
113 113 173 173 182 182 222 222 224 224 414 414
414

but i want

113, 113, 173 ,173 ,182 ,182, 222 ,222, 224 ,224,41434
,41437 ,41437)

The values thats have more than 4 numerals are whats messing things up. 
Tried ?formatC as well but couldn't get it to coerce things correctly. 
Thanks for the help

JR
-- 
View this message in context: 
http://n4.nabble.com/Drop-last-numeral-tp1012347p1012347.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Drop last numeral

2010-01-12 Thread LCOG1

The Below worked best for my purposes.  Thanks everyone.
Data-c(1131, 1132, 1731 ,1732 ,1821 ,1822, 2221 ,,
2241 ,2242,414342 ,414371 ,414372)
substr(Data,1,nchar(Data)-1) 







LCOG1 wrote:
 
 Hello all, 
   Frustrated and i know you can help 
 
 I need to drop the last numeral of each of my values in my data set.  So
 for the following i have tried the ?substring but since i have to specify
 the length, but because my data are of varying lengths it doenst work so
 well
 
 Data-c(1131, 1132, 1731 ,1732 ,1821 ,1822, 2221 ,,
 2241 ,2242,414342 ,414371 ,414372)
 Bldgid-substring(as.character(Data),1,3)
 
 returns:
 113 113 173 173 182 182 222 222 224 224 414 414
 414
 
 but i want
 
 113, 113, 173 ,173 ,182 ,182, 222 ,222, 224
 ,224,41434 ,41437 ,41437)
 
 The values thats have more than 4 numerals are whats messing things up. 
 Tried ?formatC as well but couldn't get it to coerce things correctly. 
 Thanks for the help
 
 JR
 

-- 
View this message in context: 
http://n4.nabble.com/Drop-last-numeral-tp1012347p1012492.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.