Re: [R] Finding the Min.
stat stat wrote: I want to see at which row minimum value of the second column occures. Therefore I made the following loop: [snip while-loop] Is there any more effective way to do that in terms of time consumption? I don't know about timing, but I understand that loops are somewhat slow. Assuming that x is the first column and y is the second column: D - data.frame( x = 1:10, y = rnorm(10) ) D$x[ which.min(D$y) ] See the help of which.min for more info. -Jarimatti __ R-help@stat.math.ethz.ch 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] How to detect if R is running on Mac OS X?
Philippe Grosjean wrote: This question is probably trivial, but I don't find the answer. I have code that is different for Windows, Unix/Linux and Mac OSX. The man page of .Platform tells that .Platform$OS.type is the right way to test for it... but it also tels that it returns either windows or unix. Is Mac OS X reported as unix? If yes, how do I make the difference? At least the R GUI reports .Platform$OS.type as unix on Mac OS X. Sys.info() gives some additional information: Sys.info()[sysname] sysname Darwin Note that not all Darwins are necessarily Mac OS X. The R GUI has .Platform$GUI = AQUA, which I believe is unique to Mac platform. Then again, I have no idea what R installed from sources, MacPorts or Fink reports. The GUI is probably different. Also note that the Mac OS 10.4 has BSD inside by default, so you may get away with the same code for Unix/Linux and Mac. HTH, Jarimatti Valkonen __ R-help@stat.math.ethz.ch 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] How to remove similar successive objects from a vector?
On Wed, Aug 16, 2006 at 10:42:35AM +0300, Atte Tenkanen wrote: Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 NEWVECTOR [1] 3 2 4 5 3 5 1 6 How about rle? rle(VECTOR)$values should do the same thing. Don't know about efficiency, though. -- Jarimatti Valkonen __ R-help@stat.math.ethz.ch 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] tkinsert
claude.josse wrote: But in my text window I have : x=2a=mean(c(1,2,3)) I d'like to have something like: x=2 a=mean(c(1,2,3)) AFAIK you need to separate lines with a newline character ('\n'). Put a 'tkinsert(txt, end, \n)' between the insert commands. Or append each line with '\n'. 2)My second problem, In function run: print(eval(e)) Make the evaluation in the workspace environment: print(eval(e, envir=.GlobalEnv)) Then the results are available in R console. HTH -- Jarimatti Valkonen __ R-help@stat.math.ethz.ch 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.