[R] For loops in R

2010-01-17 Thread cjmr
Hello. I've just started using R and am trying to figure out if the two codes snippets below have the same output gBest-floor(runif(popsize,min=1,max=top)) velocity[i,j]-.4* velocity[i,j] + 1 * runif(1) * (pbestsVar[i,j] - popVar[i,j]) + 1 * runif(1) * (archiveVar[gBest,j] - popVar[i,j]) and

Re: [R] optimization problem

2010-01-17 Thread Hans W. Borchers
Ravi Varadhan rvaradhan at jhmi.edu writes: Interesting! Now, if I change the cost matrix, D, in the LSAP formulation slightly such that it is quadratic, it finds the best solution to your example: Dear Ravi, I thought your solution is ingenious, but after the discussion with Erwin

Re: [R] turning an element of list into a vector

2010-01-17 Thread Jim Lemon
On 01/17/2010 04:05 AM, alessia matano wrote: Dear all, I am trying to apply the sapply function on a list, which comes out from a matrix of 25 rows and two columns, so that each element of the list, is a two column element. In my function within sapply, say f, I would like each element of the

Re: [R] Lattice: How to color the data points in splom() according to the panel they are plotted?

2010-01-17 Thread Deepayan Sarkar
On Sat, Jan 16, 2010 at 11:56 PM, Peter Ehlers ehl...@ucalgary.ca wrote: Marius Hofert wrote: Dear ExpeRts, I have the scatter plot matrix as given below. I would like the different sub-plots in the scatter plot matrix to be colored differently. How do I get all points shown in the

[R] Help using Cast

2010-01-17 Thread Steve Sidney
Dear list I am trying to count the no of occurances in a column of a data frame and there is missing data identifed by NA. I am able to melt and cast the data correctly as well as sum the occurances using margins and sum. Here are the melt and cast commands bw = melt(res, id=c(lab,r),

[R] Help using Cast (Text) Version

2010-01-17 Thread Steve Sidney
Sorry to repeat the meassage, not sure if the HTML version has been received - Apologies for duplication Dear list I am trying to count the no of occurances in a column of a data frame and there is missing data identifed by NA. I am able to melt and cast the data correctly as well as sum

[R] Strange results from Windows 7

2010-01-17 Thread Tse Ching Biu, Alan (MKT)
Hello, I am a newbie. I can run the following code stored in test.txt without error using my XP machine: x - scan(C:\\Rwork\\A.txt) x10 = filter(x, rep(1/10,10), sides=1) x x10 for(i in 10:length(x)){ if (x[i] x10[i]) diff[i]=b else diff[i]=s } However, if I run it in another PC that

[R] Choose every second value

2010-01-17 Thread Walther, Alexander
Dear list, is there a command that selects every second value from a given vector? For instance, a - c(1,2,3,4,5,6) should yield 1,3,5 and 2,4,6 which i intend to place into two seperate vectors. best Alex __ R-help@r-project.org mailing list

Re: [R] Choose every second value

2010-01-17 Thread Dimitris Rizopoulos
try this: a - c(1,2,3,4,5,6) n - length(a) a[seq(1, n, 2)] a[seq(2, n, 2)] I hope it helps. Best, Dimitris Walther, Alexander wrote: Dear list, is there a command that selects every second value from a given vector? For instance, a - c(1,2,3,4,5,6) should yield 1,3,5 and 2,4,6

Re: [R] Choose every second value

2010-01-17 Thread Patrick Burns
Instead of making two vectors, you might want to just have one matrix with two rows: amat - matrix(a, nrow=2) Then you can do: amat[1,] amat[2,] Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of The R Inferno and A Guide for the Unwilling S User)

Re: [R] Strange results from Windows 7

2010-01-17 Thread Gabor Grothendieck
Its likely that in one of your sessions you do have a diff and in the other you don't and this has nothing to do with XP vs. Windows 7. In the session with no diff, the only diff around is the function, diff, and you can't subscript a function. Try this to see what variables are in your

Re: [R] optimization problem

2010-01-17 Thread klausch
Dear Erwin, Ravi and Hans Werner, thanks a lot for your replies. I don't think I have access to Cplex and therefore probably cannot try that out but will read about MIQP. I played a bit then around with Ravi's suggestions and made also the observation that the linear cost function often found

Re: [R] Help using Cast (Text) Version

2010-01-17 Thread David Winsemius
On Jan 17, 2010, at 5:31 AM, Steve Sidney wrote: Sorry to repeat the meassage, not sure if the HTML version has been received - Apologies for duplication Dear list I am trying to count the no of occurances in a column of a data frame and there is missing data identifed by NA. I am able

Re: [R] optimization problem

2010-01-17 Thread Ravi Varadhan
Dear Hans, I agree with your comments. My intuition was that the quadratic form would be better behaved than the radical form (less nonlinear!?). So, I was hoping to see a change in behavior when the cost function was altered from a radical (i.e. sqrt) form to quadratic, but I was still

[R] enty-wise closest element

2010-01-17 Thread Andreas Wittmann
Dear R-users, i have a simple problem maybe, but i don't see the solution. i want to find the entry-wise closest element of an vector compared with another. ind1-c(1,4,10) ind2-c(3,5,11) for (i in length(ind2):1) { print(which.min(abs(ind1-ind2[i]))) } for ind2[3] it should be ind1[3] 10,

Re: [R] Lattice: How to color the data points in splom() according to the panel they are plotted?

2010-01-17 Thread Peter Ehlers
Deepayan Sarkar wrote: On Sat, Jan 16, 2010 at 11:56 PM, Peter Ehlers ehl...@ucalgary.ca wrote: Marius Hofert wrote: Dear ExpeRts, I have the scatter plot matrix as given below. I would like the different sub-plots in the scatter plot matrix to be colored differently. How do I get all points

[R] ZipF question.

2010-01-17 Thread Senlin Liang
Hey all, I read in a paper about the zipf distribution, which seems different from what i learned here. It says: we can generate a random dataset of pairs of the form (x,y). By modifying some variable Z during data generation, we can generate dataset where x and y can be closely correlated or

Re: [R] optimization problem

2010-01-17 Thread Ravi Varadhan
Klaus, I am happy to know that the quadratic cost LSAP seems to work well for you. The Hungarian algorithm is a classic for solving linear sum assignment problem, which is closely related to matching in bipartite graphs. You can google or wiki these terms to get papers and books on this

Re: [R] enty-wise closest element

2010-01-17 Thread David Winsemius
On Jan 17, 2010, at 11:00 AM, Andreas Wittmann wrote: Dear R-users, i have a simple problem maybe, but i don't see the solution. i want to find the entry-wise closest element of an vector compared with another. ind1-c(1,4,10) ind2-c(3,5,11) for (i in length(ind2):1) {

Re: [R] enty-wise closest element

2010-01-17 Thread John Kane
Is it not giving you the location of the minimum value not the value? See ind1-c(1,4,10) ind2-c(3,5,11) i=3 (ind1-ind2[i]) (aa - abs(ind1-ind2[i])) which.min(aa) --- On Sun, 1/17/10, Andreas Wittmann andreas_wittm...@gmx.de wrote: From: Andreas Wittmann andreas_wittm...@gmx.de Subject: [R]

Re: [R] Help using Cast (Text) Version

2010-01-17 Thread Steve Sidney
David Thanks, I'll try that..but no what I need is the total (1's) for each of the rows, labelled 1-6 at the top of each col in the table provided. What I guess I am not sure of is how to identify the col after the melt and cast. Steve - Original Message - From: David

Re: [R] Help using Cast (Text) Version

2010-01-17 Thread Ista Zahn
Hi Steve, It's still not clear to me what you want. Please give a minimal example so I can understand what you're trying to do. -Ista On Sun, Jan 17, 2010 at 11:56 AM, Steve Sidney sbsid...@mweb.co.za wrote: David Thanks, I'll try that..but no what I need is the total (1's) for each of

Re: [R] enty-wise closest element

2010-01-17 Thread Andreas Wittmann
Thank you very much for your quick answers. Sorry, but i forgot to explain i want to find the closest and smaller element for each entry, so ind1[3] is smaller as 11 and close to 11, ind1[2] is smaller as 5 and close to 5 and ind1[1] is smaller than 3 and close to 3. best regards Andreas

Re: [R] Help using Cast (Text) Version

2010-01-17 Thread David Winsemius
On Jan 17, 2010, at 11:56 AM, Steve Sidney wrote: David Thanks, I'll try that..but no what I need is the total (1's) for each of the rows, labelled 1-6 at the top of each col in the table provided. Part of my confusion with your request (which remains unaddressed) is what you mean

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
I don't think it is that simple because it is not a one-to-one match. In the arr data frame, there are many arrivals in a quarter hour with good weather on a given day. So I need to match the date and the quarter hour. And all of the rows in the weather data frame are times with good

Re: [R] enty-wise closest element

2010-01-17 Thread David Winsemius
On Jan 17, 2010, at 12:30 PM, Andreas Wittmann wrote: Thank you very much for your quick answers. Sorry, but i forgot to explain i want to find the closest and smaller element for each entry, so ind1[3] is smaller as 11 and close to 11, ind1[2] is smaller as 5 and close to 5 and ind1[1]

[R] plotting Formulas with greek letters and variable values (expression, substitute, paste, ...)

2010-01-17 Thread rrookie1982
Hallo together, I want to write a formula of the type http://n4.nabble.com/file/n1016112/expression.gif into my plot, where the values 1.234 and -0.567 should origin from variables in the program. The threads in this forum gave me some ideas that the functions expression(), paste(), and

Re: [R] plotting Formulas with greek letters and variable values (expression, substitute, paste, ...)

2010-01-17 Thread Uwe Ligges
On 17.01.2010 18:47, rrookie1982 wrote: text(0,7.5,substitute(expression(paste(symbol(t),(A) = ,c1 + lg(A^c2),sep=)),list(c1=0,456,c2=-0.123)),pos=4) It is much easier, just write the formula down in R syntax and substitute the relevant variables as in: text(0, 7.5, substitute(tau(A) ==

Re: [R] Comparing dates in dataframes

2010-01-17 Thread David Winsemius
On Jan 17, 2010, at 12:37 PM, James Rome wrote: I don't think it is that simple because it is not a one-to-one match. In the arr data frame, there are many arrivals in a quarter hour with good weather on a given day. So I need to match the date and the quarter hour. And all of the rows

Re: [R] plotting Formulas with greek letters and variable values (expression, substitute, paste, ...)

2010-01-17 Thread Gabor Grothendieck
Try bquote: a - 0.1; b - 0.2 plot(0, main = bquote(tau(A) == .(a)*lg(A^.(b On Sun, Jan 17, 2010 at 12:47 PM, rrookie1982 dess...@uni-bonn.de wrote: Hallo together, I want to write a formula of the type http://n4.nabble.com/file/n1016112/expression.gif into my plot, where the

Re: [R] Help using Cast (Text) Version

2010-01-17 Thread Steve Sidney
Bingo, I knew it was something simple and that I wasn't seeing the wood for the trees. David, Ista Apologies for the vague description, which I thought was clear enough, but yes I now think that I understand that I need to count the 1's and be able to sum the total of 1' and 0's by

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
On 1/17/10 1:06 PM, David Winsemius wrote: On Jan 17, 2010, at 12:37 PM, James Rome wrote: I don't think it is that simple because it is not a one-to-one match. In the arr data frame, there are many arrivals in a quarter hour with good weather on a given day. So I need to match the date

Re: [R] Comparing dates in dataframes

2010-01-17 Thread jim holtman
SInce you provided no data, it is hard to determine how to compare. If you also want the date, then the following will work: arr$GoodWeather - arr$quarter %in% gw$quarter arr$date %in% gw$date If your quarter is just the minutes of arrival, you may have to convert that to the appropriate

[R] coplots with missing values

2010-01-17 Thread LisaB
Hello - I'm trying to construct a coplot to check the residuals conditioned on a factor using the following formula, however I keep getting an error message. I've used the same formula for another data set and it worked fine - the only difference is that now I have missing values for each level

Re: [R] Error: object of type 'closure' is not subsettable

2010-01-17 Thread Rolf Turner
I thought it would be possible to make rep() work for functions by writing a method for the function class. I tried: rep.function - function(x,...) { times - as.list(...)[[1]] rslt - vector(list,times) rslt[1:times] - list(x) rslt } But then doing rep(sin,2) still gave an error

Re: [R] Strange results from Windows 7

2010-01-17 Thread Joshua Wiley
Hello Alan, Following up on Gabor's suggestion, if you have different packages loaded, one of those packages could have a function 'diff' that would not show up with a call to ls() so you could also try search() which will show you what packages are loaded. HTH, Joshua On Sun, Jan 17, 2010

Re: [R] Strange results from Windows 7

2010-01-17 Thread Rolf Turner
On 18/01/2010, at 9:02 AM, Joshua Wiley wrote: Hello Alan, Following up on Gabor's suggestion, if you have different packages loaded, one of those packages could have a function Object? 'diff' that would not show up with a call to ls() so you could also try search() which will

Re: [R] enty-wise closest element

2010-01-17 Thread Charles C. Berry
On Sun, 17 Jan 2010, Andreas Wittmann wrote: Thank you very much for your quick answers. Sorry, but i forgot to explain i want to find the closest and smaller element for each entry, so ind1[3] is smaller as 11 and close to 11, ind1[2] is smaller as 5 and close to 5 and ind1[1] is smaller

Re: [R] optimization problem

2010-01-17 Thread Erwin Kalvelagen
No, I cannot find counterexamples, so that actually seems to give identical solutions! That is fantastic. I guess my homework is now convince myself we can go from this quadratic objective sum_i,j [ sum_k P[i,k]*G[k,j] - I[i,j] ]^2 to a linear one: sum_i,j c[i,j]*P[i,j] Thanks ! Erwin

Re: [R] weighting (survey) data

2010-01-17 Thread Vera
2010/1/16 Thomas Lumley tlum...@u.washington.edu: On Sat, 16 Jan 2010, Vera wrote: Thanks for your help so far, everyone. Thomas: I haven't looked very deep into the survey package yet, so I don't know if what I'm looking for is actually missing or if I just haven't found it yet. What is

Re: [R] Help using Cast (Text) Version

2010-01-17 Thread Steve Sidney
Well now I am totally baffled !! Using sum( !is.na(b[,3])) I get the total of all col 3 except those that are NA - Great solves the first problem What I can't seem to do is use the same logic to count all the 1's in that col, which are there before I use the cast with margins. So it

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
Thank you Dennis. arr$gw - as.numeric(weather$Date == arr$Date arr$quarter %in% weather$quarter) seems to be what I want to do, but in fact, with the full data set, it misidentifies the rows, so I think the error message must mean something. arrr$Date -

[R] How to convert character matrix or data.frame to numeric?

2010-01-17 Thread ivan popivanov
Hello, This turned out to be surprisingly hard for me: Let's say I have mm = matrix(as.character(seq(1,30, 1)), nrow=3); mm [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 4 7 10 13 16 19 22 25 28 [2,] 2 5 8 11 14 17 20 23 26 29 [3,] 3 6 9 12 15 18 21 24 27

Re: [R] optimization problem

2010-01-17 Thread Hans W. Borchers
Ravi Varadhan rvaradhan at jhmi.edu writes: Dear Hans, I agree with your comments. My intuition was that the quadratic form would be better behaved than the radical form (less nonlinear!?). So, I was hoping to see a change in behavior when the cost function was altered from a radical

Re: [R] How to convert character matrix or data.frame to numeric?

2010-01-17 Thread Gabor Grothendieck
Try this: class(mm) - numeric On Sun, Jan 17, 2010 at 5:17 PM, ivan popivanov ivan.popiva...@hotmail.com wrote: Hello, This turned out to be surprisingly hard for me: Let's say I have mm = matrix(as.character(seq(1,30, 1)), nrow=3); mm     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]

[R] Problem with EXtRemes GUI [SEC=UNCLASSIFIED]

2010-01-17 Thread Augusto.Sanabria
Dear list-members, I am moving some of my heavy processing to a new machine (running SuSE Enterprise Linux 10 SP2) and I need packages 'extRemes' and 'ismev'loaded within a BATCH process (to calculate a confidence interval in a GPD model using the profile likelihood method). My problem is that

Re: [R] How to convert character matrix or data.frame to numeric?

2010-01-17 Thread Ben Tupper
Hi, I find the following works in R 2.10.1 on Mac OSX. m = matrix(rep(3, 30), 5,6) m [,1] [,2] [,3] [,4] [,5] [,6] [1,] 3 3 3 3 3 3 [2,] 3 3 3 3 3 3 [3,] 3 3 3 3 3 3 [4,] 3 3 3 3 3 3 [5,] 3 3 3 3 3 3 apply(m, 1,as.numeric) [,1] [,2] [,3] [,4] [,5] [1,]3

Re: [R] How to convert character matrix or data.frame to numeric?

2010-01-17 Thread Rolf Turner
In respect of your matrix problem: (1) mode(mm) - numeric OR: (2) mm - apply(mm,2,as.numeric) In respect of your data frame problem: as.data.frame(lapply(X,as.numeric)) (where X is your data frame) should work. This will of course convert every column of your data frame to numeric

Re: [R] Help using Cast (Text) Version

2010-01-17 Thread David Winsemius
On Jan 17, 2010, at 4:37 PM, Steve Sidney wrote: Well now I am totally baffled !! Using sum( !is.na(b[,3])) I get the total of all col 3 except those that are NA - Great solves the first problem What I can't seem to do is use the same logic to count all the 1's in that col,

Re: [R] Comparing dates in dataframes

2010-01-17 Thread David Winsemius
My guess (since we still have no data on which to test these ideas) is that you need either to merge() or to use a matrix created from the dates and qtr-hours entries in gw, since matching on dates and hours separately will not uniquely classify the good qtr-hours within their proper

Re: [R] How to convert character matrix or data.frame to numeric?

2010-01-17 Thread Ben Tupper
Hello again, On Jan 17, 2010, at 5:42 PM, Rolf Turner wrote: Notice that your output is 6 x 5 whereas your input is 5 x 6. Now *what* did you do wrong? Whoa! Let's try that again, but with a better example. X = matrix(as.character(1:6),2,3) X [,1] [,2] [,3] [1,] 1 3 5 [2,] 2

Re: [R] weighting (survey) data

2010-01-17 Thread Thomas Lumley
On Sun, 17 Jan 2010, Vera wrote: 2010/1/16 Thomas Lumley tlum...@u.washington.edu: On Sat, 16 Jan 2010, Vera wrote: Thanks for your help so far, everyone. Thomas: I haven't looked very deep into the survey package yet, so I don't know if what I'm looking for is actually missing or if I just

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
Here are some sample data sets. I also tried making a combined field in each set such as adq=paste(as.character(arr$Date), as.character(arr$quarter)) and similarly for the weather set, so I have unique single things to compare, but that did not seem to help much. Thanks, Jim On 1/17/10 5:50 PM,

Re: [R] Help using Cast (Text) Version

2010-01-17 Thread Simon Knapp
Hi Steve, These might help. #generate some example data similar to your original email, with one extra line containing all NAs (first col included to provide similarity with your data) labs - c('4er66', '4gcyi', '5d3hh', '5d3wt', 'v3st5', 'a22g5', 'b5dd3', 'g44d2', 'z') dat - scan() 1 NA 1

[R] How to learn content-type

2010-01-17 Thread cihan inan
I want to learn content-type of a file. what should I do? In my code I want to do: I give an url to download. the function learns the content-type and if it is a text file downloads it. else will raise an error. [[alternative HTML version deleted]]

Re: [R] coplots with missing values

2010-01-17 Thread Simon Knapp
Never used coplot, but why not try removing the rows with missing variables? Perhaps with: dat - cbind(E2=resid(baea.ancova6, type = normalized), year, population) coplot(E2~year|population, data=dat[apply(dat, 1, function(x) !any(is.na (x))),]) Regards, Simon Knapp On Mon, Jan 18, 2010 at 6:54

Re: [R] Comparing dates in dataframes

2010-01-17 Thread David Winsemius
But, but, but there is no weather goodness variable in weather?!?!?! str(weather) 'data.frame': 155 obs. of 4 variables: $ Date :Class 'Date' num [1:155] 14245 14245 14245 14245 14245 ... $ minute : int 5 15 30 45 0 15 30 45 0 15 ... $ hour : int 15 15 15 15 17 17 17 17 18

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
Any entry in the weather data is a good day. That is the point. And please ignore my mistake about the quarters getting too large in weather. I am being swamped with versions, and it does not matter for this purpose.. so, the bad weather days are not in the weather data set. I am trying to get

[R] Sub-matrixes that are linked to the Base matrix

2010-01-17 Thread Friedrich
Hello, I'm am in the process of trying to port a RATS functions to R and have the problem, that RATS allows for the creation of submatrixes that are linked to their basematrix. Basically it should work like this: a = matrix(1:(4*3),4,3) a # [,1] [,2] [,3] # [1,]159 # [2,]2

[R] function to set log(0)=0 not working on tables or vectors

2010-01-17 Thread maiya
There must be a very basic thing I am not getting... I'm working with some entropy functions and the convention is to use log(0)=0. So I wrote a function: llog-function(x){ if (x ==0) 0 else log(x) } which seems to work fine for individual numbers e.g. llog(0/2) [1] 0 but if I try whole

Re: [R] function to set log(0)=0 not working on tables or vectors

2010-01-17 Thread Peter Ehlers
Are you telling us the whole story? Or did you also get a warning message which should have twigged the answer for you? Try ifelse() instead of if(). -Peter Ehlers maiya wrote: There must be a very basic thing I am not getting... I'm working with some entropy functions and the convention is

Re: [R] function to set log(0)=0 not working on tables or vectors

2010-01-17 Thread David Winsemius
On Jan 17, 2010, at 8:17 PM, maiya wrote: There must be a very basic thing I am not getting... I'm working with some entropy functions and the convention is to use log(0)=0. I suppose the outcome of that effort may depend on whether you have assumed the needed godlike capacities to

Re: [R] function to set log(0)=0 not working on tables or vectors

2010-01-17 Thread Ben Bolker
David Winsemius dwinsemius at comcast.net writes: On Jan 17, 2010, at 8:17 PM, maiya wrote: There must be a very basic thing I am not getting... I'm working with some entropy functions and the convention is to use log(0)=0. I suppose the outcome of that effort may depend on

Re: [R] Confusion in 'quantile' and getting rolling estimation of sample quantiles

2010-01-17 Thread Saji Ren
Gabor, about problem 1. , now I understand. But in problem 2. , I do as your recommandation. and it still doesn't work. I wonder is there any detail introduction about the form of the 'FUN' in the 'rollapply'? Can you help me again? Thank you very much! Best regard Saji There is no quantile

Re: [R] Confusion in 'quantile' and getting rolling estimation of sample quantiles

2010-01-17 Thread Saji Ren
sorry for bothering you again, the problem solved. the command should be : uprange=rollapply(zoo(x),width=10,FUN=function(x)quantile(x,0.8),align='right') Gabor Grothendieck wrote: There is no quantile method defined for zoo objects so it falls through to the default method but that method

Re: [R] plotting Formulas with greek letters and variable values (expression, substitute, paste, ...)

2010-01-17 Thread rrookie1982
rrookie1982 wrote: I want to write a formula of the type http://n4.nabble.com/file/n1016112/expression.gif into my plot, where the values 1.234 and -0.567 should origin from variables in the program. Uwe Ligges-3 wrote: It is much easier, just write the formula down in R

[R] a question about multilevelmodel

2010-01-17 Thread 孟欣
Hello all: I've read the document named A Brief Introduction to R, the multilevel package and the nlme package. At p68, one can transform the dataset to the required format by using make.univ. I wanna know,how the new variable MULTDV is calculated(can you show me the formula if possible