Displaying 20 results from an estimated 20000 matches similar to: "Defining functions - an interesting problem"
2009 May 04
4
Splitting a vector into equal groups
Hi All,
I have vector of length 52, say, x=sample(30,52,replace=T). I want to
sort x and split into five *nearly equal groups*. Note that the
observations are repeated in x so in case of a tie I want both the
observations to fall in same group.
This seems a very common task to do, but still I couldn't find an R
function to do this. Any help would be highly appreciated.
Regards
Utkarsh
2009 Jun 30
4
R version-2.9.1 for Linux
Hi All,
I am currently using R version 2.8.1 on linux cent os 4.4 (i386) and
want to upgrade to version 2.9.1. It seems to me that version-2.9.1 is
it not for my OS.
Am I right?
Regards
Utkarsh
[[alternative HTML version deleted]]
2010 Dec 17
1
[Fwd: adding more columns in big.matrix object of bigmemory package]
Hi,
With reference to the mail below, I have large datasets, coming from various
different sources, which I can read into filebacked big.matrix using library
bigmemory. I want to merge them all into one 'big.matrix' object. (Later, I
want to run regression using library 'biglm').
I am unsuccessfully trying to do this from quite some time now. Can you
please
2009 May 18
2
intermediate iterations of stepwise regression
Hi all,
I am performing a stepwise regression by running the "step" function on
an "lm" object. Now I want to save the intermediate iterations. I know
the argument trace=T will print it on the console, but I rather want to
assign it to some R object or may be output it in a CSV or text file.
Any help will be appreciated.
Regards
Utkarsh
2009 Nov 23
3
FUN argument to return a vector in aggregate function
Hi All,
I am currently doing the following to compute summary statistics of
aggregated data:
a = aggregate(warpbreaks$breaks, warpbreaks[,-1], mean)
b = aggregate(warpbreaks$breaks, warpbreaks[,-1], sum)
c = aggregate(warpbreaks$breaks, warpbreaks[,-1], length)
ans = cbind(a, b[,3], c[,3])
This seems unnecessarily complex to me so I tried
> aggregate(warpbreaks$breaks, warpbreaks[,-1],
2009 Jun 02
2
bigmemory - extracting submatrix from big.matrix object
I am using the library(bigmemory) to handle large datasets, say 1 GB,
and facing following problems. Any hints from anybody can be helpful.
_Problem-1:
_
I am using "read.big.matrix" function to create a filebacked big matrix
of my data and get the following warning:
> x =
read.big.matrix("/home/utkarsh.s/data.csv",header=T,type="double",shared=T,backingfile
2011 May 14
2
calling "exists" function inside another function is not working
Hi all,
I want to define a function such that one of its argument if passed do one
thing and if not passed do the second thing. So basically, I have to check
whether the argument is passed or not inside the function. I am trying to
use 'exists' function to do this.
> f = function(a,b){exists("b")}
> f(a=3, b=4)
[1] TRUE
This is working as expected.
2011 May 14
2
calling "exists" function inside another function is not working
Hi all,
I want to define a function such that one of its argument if passed do one
thing and if not passed do the second thing. So basically, I have to check
whether the argument is passed or not inside the function. I am trying to
use 'exists' function to do this.
> f = function(a,b){exists("b")}
> f(a=3, b=4)
[1] TRUE
This is working as expected.
2009 Apr 30
2
problem in as.date
I never understood that why is the value returned by as.date function in
the library(survival) never matches with the description given in the
help file:
Following is the extract from ?as.date
Description:
Converts any of the following character forms to a Julian date:
8/31/56, 8-31-1956, 31 8 56, 083156, 31Aug56, or August 31 1956.
Usage:
as.date(x, order = "mdy", ...)
2009 Sep 14
1
setting plotting device
Hi All,
I have recently *re*-installed R-2.9.1 in my Linux machine. Since then,
I am unable to plot using the usual interactive device.
> plot(1:10)
This plots in a pdf file "Rplots.pdf" in my working directory.
> sessionInfo()
R version 2.9.1 (2009-06-26)
i686-pc-linux-gnu
locale:
2009 Jun 16
1
Testing if all elements are equal in a vector/matrix
Hi All,
There are several replies to the question below, but I think there must
exist a better way of doing so.
I just want to check whether all the elements of a vector are same. My
vector has one million elements and it is highly likely that there are
distinct elements in the first few itself. For example:
> x = c(1,2,rep(1,100000))
I want the answer as FALSE, which is clear from the
2009 Jul 03
2
bigglm() results different from glm()
Hi Sir,
Thanks for making package available to us. I am facing few problems if
you can give some hints:
Problem-1:
The model summary and residual deviance matched (in the mail below) but
I didn't understand why AIC is still different.
> AIC(m1)
[1] 532965
> AIC(m1big_longer)
[1] 101442.9
Problem-2:
chunksize argument is there in bigglm but not in biglm, consequently,
2009 Jun 01
1
installing sn package
Hi r-users,
I want to use the sn package but I got the following message:
> install.packages(repos=NULL,pkgs="c:\\Tinn-R\\sn_0.4-12.zip")
Warning: package 'sn' is in use and will not be installed
updating HTML package descriptions
I did tried to do it a few times but it gives the same message.
________________________________
From:
2008 Mar 03
1
using 'lrm' for logistic regression
Hi R,
I am getting this error while trying to use 'lrm' function with nine
independent variables:
> res =
lrm(y1994~WC08301+WC08376+WC08316+WC08311+WC01001+WC08221+WC08106+WC0810
1+WC08231,data=y)
singular information matrix in lrm.fit (rank= 8 ). Offending
variable(s):
WC08101 WC08221
Error in j:(j + params[i] - 1) : NA/NaN argument
Now, if I take choose only four
2006 Aug 29
2
lattice and several groups
Dear R-list,
I would like to use the lattice library to show several groups on
the same graph. Here's my example :
## the data
f1 <- factor(c("mod1","mod2","mod3"),levels=c("mod1","mod2","mod3"))
f1 <- rep(f1,3)
f2 <-
2009 Sep 18
3
Error: length(f1) == length(f2) is not TRUE
Dear R users,
I am trying to fit an lmer model with only random effects which is giving
me the following error:
Error : length(f1) == length(f2) is not TRUE
In addition: Warning messages:
1: In P1L55:family :
numerical expression has 390 elements: only the first used
2: In P1L55:family :
numerical expression has 390 elements: only the first used
I am trying to extract variance components
1999 Nov 22
1
Fit with constraints (fwd)
I would like to fit a model of the type
Y = Xf + e
where f are cover fractions (or percent cover). Therefore,
I must constrain the fit to
1. sum(f) = 1
2. 0<= f <=1
How can I introduce these 2 constraints in a ML fit?
Currently, I'm using nlregb and I'm using the "upper and
low" keywords to set the bounds and
use the following to ensure that sum(f) = 1:
let's say
2013 Jan 23
1
Arguments passing through dot-dot-dot lose ability to check for missing()?
Hi R-devel. Is the following behavior in g1() and h1() expected? It seems
to make "..." arguments work slightly differently from named arguments.
#missing() has the property that it looks "up the chain"
#for example, "z" can be missing in f3 even if
#that argument did have a name ("y") in f2
f1 <- function(x, ...) {
cat("In f1, missing(x) is
2007 Mar 09
1
Applying some equations over all unique combinations of 4 variables
#I have a data set that looks like this. A bit more
complicated actually with
# three factor levels but these calculations need to
be done on one factor at a
#I then have a set of different rates that are applied
#to it.
#dataset
cata <- c( 1,1,6,1,1,2)
catb <- c( 1,2,3,4,5,6)
doga <- c(3,5,3,6,4, 0)
data1 <- data.frame(cata, catb, doga)
rm(cata,catb,doga)
data1
# start rates
#
2009 Dec 29
2
pass functions and arguments to function
Hi,
I wonder how to pass several functions and their arguments as arguments to
a function. For example, the main function is
f = function(X ) {
process1(X)
...
process2(X)
}
I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2),
g3(X, par3). par1, par2 and par3 are parameters and of different types. I
would like to pass g1, g2, g3 and their arguments to f and g1,