Displaying 20 results from an estimated 8000 matches similar to: "Formatting numbers"
2009 Apr 24
2
argument 'exclude' in function xtabs
Dear all
I was willing to use argument 'exclude' in function xtabs to remove some
levels of factors (xtabs help page says '"exclude: a vector of values to be
excluded when forming the set of levels of the classifying factors").
I tried:
> mydata <- data.frame(
treatment = c("B", "A", "C", "C", "B",
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
2009 Apr 25
2
Changing gird marks in ggplot2
Hi,
When I zoom into a graph created in ggplot2 with the
coord_cartesian(ylim=c(0,5)) option, I have no values labelled on my y-axis.
For this graph ggplot2 only puts labels the y-axis at intervals of 10 (i.e.
0, 10, 20, ...). However, the major portion of the graph I am interested in
is located between the values of 0 and 5 on the y-axis (thus why I am
zoooming). How can I coerce ggplot2 into
2009 Apr 26
3
3 questions regarding matrix copy/shuffle/compares
Hello all,
I have the following function call to create a matrix of POP_SIZE rows
and fill it with bit strings of size LEN:
pop=create_pop_2(POP_SIZE, LEN)
I have 3 questions:
(1) If I did
keep_pop[1:POP_SIZE] == pop[1:POP_SIZE]
to keep a copy of the original data structure before manipulating
'pop' potentially, would this make a deep copy or just shallow? Ie
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
2010 Jan 10
1
lme4 and function 'cholmod_start' not provided by package 'Matrix' / Ubuntu
Hello all,
Using Ubuntu 9.04 and R 2.8.1.
For a project I need to use the Zelig package, which in turn wants to
use the lme4 package. When trying to use Zelig and it tries to its required
packages I get the following error message.
Error in dyn.load(file, DLLpath = DLLpath, ...) :
function 'cholmod_start' not provided by package 'Matrix'
Error in loadModelDeps(model) :
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 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/
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
2003 May 14
2
how to include 'NA's in xtabs?
Hello!
I have a dataset with NA's in some variables (factors), for example:
$ P67 : Factor w/ 2 levels "-","+": NA 2 1 NA NA 2 1 1 2 NA ...
I need to use 'xtabs' like
xtabs(~x$P67)
It works well and produces something like this:
x$P67
- +
779 1318
but i want to compute NA's too, like this:
x$P67
- + NA
779 1318 137
I am trying
2009 May 23
1
optimizing function over x,y
Hello all,
I would like to maximize or minimize a given math function over a
specific set of values.
I was checking out Wolfram Alpha (http://www70.wolframalpha.com/)
and it can do simple optimization problems in math, such as
maximize 15*x - x**2 over 0 to 15
(http://www70.wolframalpha.com/input/?i=maximize+15*x+-+x**2+over+0+to+15)
which finds the maximum value and input for x in
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
2008 Jul 23
1
Sample on dataframe
Hi
I'm looking for solution or function which I can use to sample data
frame, to obtain new (smaller) data frame similar to sample() function
Jarek Jasiewicz
2015 Feb 09
3
xtabs and NA
Hi
I haven't found a way to produce a tabulation from factor data with NA
values using xtabs. Please find a minimal example below, it's also on
R-pubs [1]. Tested with R 3.1.2 and R-devel r67720.
It doesn't seem to be documented explicitly that it's not supported.
From reading the code [2] it looks like the relevant call to table()
doesn't set the "useNA"
2009 Sep 04
1
Problem with xtabs(), exclude=NULL, and counting NA's
Hi all,
I cannot get xtabs to count NA's like I expect. Below is a sample session, and
note that the last two calls to xtabs() yield exactly the same thing.
I am running R-2.5.0 -- if there was a bug in xtabs that got fixed, I would love
to know about it. If there is a bug tracker somewhere, I can file it too. It
isn't my fault that the server is so ridiculously outdated, but I would
2010 Apr 18
3
xtabs() of proportions, and naming a dimension (not a row)
Hi,
xtabs() creates a table of counts. I want a table of proportions -- that
is, I want to divide every vector (along a particular dimension) by its sum.
The tiny example below does that. The call to xtabs() creates a matrix "A"
with dimensions ("x1","x2","y"). I transform "A" using aperm() and aaply()
to get the matrix "B". The