Displaying 20 results from an estimated 10000 matches similar to: "optimizing function over x,y"
2009 May 24
1
using optimize() correctly ...
Hi,
I am trying to use the optimize function to optimize a function. The
results I am getting don't agree with what I compute on my own and
when I look at the graph of
f(x) = 100 + ((x-10)**2 + (x-10)) * cos(x-10), where -10 <= x <= 10
in gnuplot.
I suspect I am making a mistake in the usage of the R optimize
function, perhaps someone could point out where?
>
2009 Apr 19
3
flip certain bits in vector
I have a string of binary values, and I would like to flip certain
bits in a set of positions.
Let's say the
vector p contains position [1, 3, 5, 7]
vector b contains bits [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
result r should be [0, 1, 0, 0, 0, 0, 0, 0, 1, 0]
in pseudo code this would be something like
---
r = c()
for (i in 1:10)
if (i in p)
r = c(r, flip[i])
r
----
2009 Aug 28
6
Google's R Style Guide
Perhaps most of you have already seen this?
http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html
Comments/Critiques?
Thanks,
Esmail
ps: Reminds me of PEP 8 for Python
http://www.python.org/dev/peps/pep-0008/
Maybe not that surprising since Python is also one of the main languages
used by Google.
2008 May 09
2
which.max2()
Hello,
which.max() only returns one index value, the one for the
maximum value. If I want the two index values for the two
largest values, is this a decent solution, or is there a
nicer/better R'ish way?
max2 <-function(v)
{
m=which.max(v)
v[m] = -v[m]
m2=which.max(v)
result=c(m, m2)
result
}
Seems to work ok.
Thanks,
Esmail
2008 Jun 12
3
Adding new columns to (output) data - e.g., read 5 cols write 8
Hello, I have the following task I'd like to accomplish:
A file contains 5 columns of data (several hundred rows), let's call
them a, b, c, d and e (ie these are their column headers)
I also have a set of definitions, e.g.,
f = a + b
g = a * 3
h = c + d
etc.
I would like to write out a new .rda file that contains columns
a b c d e f g h etc.
I.e. , the original data plus new columns
2009 Apr 27
3
Formatting numbers
I've been trough the R documentation for about half an hour and it's not
clear to me how to do this:
I need to format to character a series of integers from 1 to 1000, and I
like them to look like
"0001" "0002", "0059", "0123" and so on. Padded with zeroes to have four
digits.
Cheers!
Mario.
r-help-request at r-project.org wrote:
> Send
2008 May 07
1
Automatically generating new column names (and columns)
Once again I need to tap into the collective knowledge here.
Let's say I have the following columns and data below
Y X1 X2 X3 X4
I would like to generate additional new columns and column names
(ie the data would be squared - and I'd like the column names to
reflect this) like:
Y X1 X2 X3 X4 X1^2 X2^2 X3^2 X4^2
I believe I can compute the values correctly with the code below, but
I
2001 Jan 14
2
Help
Dear sir,
I am using R in windows. I want to extend R Memory
size.
I use the following command, but unfortunately it
doesn't work.
-- vsize=15M --nsize=1000K
Your help is appreciated.
Thanks,
Esmail Amiri.
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
2009 Apr 26
4
comparing matrices
I'm trying to compare two matrices made up of bits.
doing a simple comparison of
matA == matB
yields this sort of output.
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] FALSE TRUE FALSE TRUE TRUE FALSE
[2,] TRUE TRUE TRUE TRUE TRUE TRUE
[3,] FALSE TRUE FALSE FALSE FALSE TRUE
[4,] FALSE TRUE TRUE FALSE FALSE FALSE
[5,] TRUE TRUE TRUE TRUE FALSE FALSE
[6,] TRUE TRUE
2010 Feb 24
2
sprintf + integer(0) problem
Hello all,
I am stuck with R v2.8.0 under Linux for the time being and I am
running into a small problem that doesn't exist under 2.9.x and 2.10.x
with sprintf.
If I have the following code segment to help me determine the column
number for a specific column header/label:
nn = names(Dataset)
s = "Group"
c = which(nn==s)
cat(sprintf('found %s in col %d\n', s, c))
2010 Feb 15
1
argh .. if/else .. why?
Hello, would someone please help explain the following inconsistency
in the if/else statement to me?
The format of the if/else #3 below is ok, but if/else #1 is not? (I get
an "unexpected else" type error.) In order for it to work I have to use
if/else #2
Thanks .. maybe there is some reason for this, but this looks very
inconsistent to me.
R version 2.10.1 (2009-12-14)
Ubuntu 9.04
2009 Feb 18
2
how to randomly eliminate half the entries in a vector?
(sorry if this is a duplicate-problems with posting at my end)
----
Hello all,
I need some help with a nice R-idiomatic and efficient solution to a
small problem.
Essentially, I am trying to eliminate randomly half of the entries in
a vector that contains index values into some other vectors.
More details:
I am working with two strings/vectors of 0s and 1s. These will contain
about 200
2006 Jun 26
2
Inverse Error Function
Do any of the R libraries have an implementation of the Inverse Error
Function (Inverse ERF)?
ref:
http://mathworld.wolfram.com/InverseErf.html
http://functions.wolfram.com/GammaBetaErf/InverseErf/
Thanks,
Nathan
[[alternative HTML version deleted]]
2003 Jan 24
4
new function: showcolors {base}
I propose to add a function that allows
to display colors selected by a text pattern
or by color vectors in a plot.
Wolfram Fischer
#--- showcolors.R
showcolors <-
function(
col = "red"
, index = NULL
, pie = TRUE
, lwd = 6
, cex = 1.0
, main = NULL
, sub = NULL
, ...
){
n.colors <- length( col )
if( n.colors > 1 ){
main <- deparse( substitute( col ) )
2004 Jul 08
2
Getting elements of a matrix by a vector of column indice s
See if the following helps:
> m <- outer(letters[1:5], 1:4, paste, sep="")
> m
[,1] [,2] [,3] [,4]
[1,] "a1" "a2" "a3" "a4"
[2,] "b1" "b2" "b3" "b4"
[3,] "c1" "c2" "c3" "c4"
[4,] "d1" "d2" "d3" "d4"
[5,]
2010 Mar 11
2
Comparing matrices
Hello all,
I have two matrices, pop and pop2, each the same number of rows and
columns that I want to compare for equality. I am concerned about
efficiency in this operation.
I've tried a few things without success so far. Doing something simple like:
if (pop==pop2) { cat('equal') } else { cat('NOT equal') }
results in the warning:
1: In if (pop == pop2) { :
the
2002 May 03
2
sub() of matrix returns a vector and not a matrix
Is there a simple possibility
to become directly a matrix
from a call of sub() on a matrix?
--------- START OF LOGFILE ----------------
# R 1.4.1
> a <- matrix( letters[1:6], 2, 3 )
# a is a matrix
> print( a )
[,1] [,2] [,3]
[1,] "a" "c" "e"
[2,] "b" "d" "f"
> b <- sub( '(.)', '-\\1-', a )
2004 Oct 04
11
inverse function of order()
I have:
d <- sample(10:100, 9)
o <- order(d)
r <- d[o]
How I can get d (in the original order), knowing only r and o?
Thanks - Wolfram
2006 Oct 31
1
Re: Ugly menu/dialog font of applications, using debian
> Message: 5
> Date: Mon, 30 Oct 2006 13:46:57 +0100
> From: Jens Gulden <mail@jensgulden.de>
> Subject: Re: [Wine] Ugly menu/dialog font of applications, using
> debian sarge and wine 0.9.8 and 0.9.22
> To: wine-users@winehq.org
> Message-ID: <4545F441.4080606@jensgulden.de>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hallo Wolfram,
2010 Apr 08
1
formatting a result table (number of digits)
Hello,
Is there an easy way to format the output of a result table that R
generates from a regression? I like the table, but would like to
limit the number of decimal points in the entries if possible.
For instance I would like only 3 digits of precision for the Value,
Std.Error. (And if it would be easy to get rid of scientific notation,
that would be good to know too). So ideally keep the