Displaying 20 results from an estimated 8000 matches similar to: "Help on computing a matrix from another matrix in R"
2007 Jun 26
1
A really simple data manipulation example
In response to those who asked for a better explanation of what the
Vilno software does, here's a simple example that gives some idea of
what it does.
LABRESULTS is a dataset with multiple rows per patient , with lab
sodium measurements. It has columns: PATIENT_ID, VISIT_NUM, and
SODIUM.
DEMO is a dataset with one row per patient, with demographic data.
It has columns: PATIENT_ID, GENDER.
2006 Apr 17
1
Function for computing the difference between 2 dates in months
Folks:
With the help of David L. Reiner, I've developed a function that
computes the number of months between 2 dates, x and y.
num.months <- function ( x , y )
{
x <- as.Date( x )
y <- as.Date( y )
seeq <- seq(from=x , to=y , by="months")
ans <- length( seeq ) - 1
if ( max( seeq) > y ) ans <- ans -1
ans
}
To ease your reading this function, I've
2008 Nov 06
0
problems executing a bulk load with SQL server
Hello,
New to this forum so I hope the content is appropriate...
I was building a some code to maniputlate some data. Given the bulk of it
(the csv is about a GB), I opted to use a database.
The setup, which may be part of the issue is that the SQL is one remote
machine (call it 'A'), the disk that contains the data is on some other
remote drive - call it 'B' and the server on
2010 Jul 29
1
Using 'dimname names' in aperm() and apply()
I think that the "dimname names" of tables and arrays could make
aperm() and apply() (and probably some other functions) easier to use.
(dimname names are, for example, created by table() )
The use would be something like:
--
x <-table( from=sample(3,100,rep=T), to=sample(5,100,rep=T))
trans <- x / apply(x,"from",sum)
y <- aperm( trans,
2007 Jul 28
1
Error when using the cat function
Is the following developed in my console output a recognized bug or am I using the cat function incorrectly?
Thanks,
Stan
> ifelse(class(data[[n]])!="factor",{print("yes")},{print("no")})
[1] "yes"
[1] "yes"
> ifelse(class(data[[n]])!="factor",{cat("yes")},{cat("no")})
yesError in ans[test & !nas] <-
2005 Aug 22
2
problem building dendrograms to use with heatmap()
Hi,
I'm trying to build dendrograms to pass to heatmap().
The dendrograms I build plot properly, but when I pass them to heatmap() I get
the error message "row dendrogram ordering gave index of wrong length" (see
output log below).
I looked in the code of heatmap() and saw that the error was due to a NULL
return value from order.dendrogram(), which in turn got a NULL return value
2007 May 23
1
Readline - wait for user input
Hi,
I've seen various posts on this question, but still can't get the code
right.
If I run the following code one line at a time, it works fine. If I run
it together as a block, however, it doesn't wait for the input and gives
an error.
There must be a way to have are pause/wait for an answer, but I can't
seem to find it. Thanks! J
Code:
choosefunction <-
2011 May 02
2
Lasso with Categorical Variables
Hi! This is my first time posting. I've read the general rules and
guidelines, but please bear with me if I make some fatal error in
posting. Anyway, I have a continuous response and 29 predictors made
up of continuous variables and nominal and ordinal categorical
variables. I'd like to do lasso on these, but I get an error. The way
I am using "lars" doesn't allow for the
1999 Nov 11
2
dimname'less array breaks apply (PR#318)
<<insert bug report here>>
> apply(array(1:20,c(2,2,5)),2:3,function(x) x)
Error: length of dimnames must match that of dims
>
Changing:
dimnames = if (is.null(dn.ans)) list(ans.names, NULL) else c(list(ans.names), dn.ans)
To:
dimnames = if (length(dn)==0) NULL else
if (is.null(dn.ans)) list(ans.names, NULL) else c(list(ans.names), dn.ans)
seems to fix this.
Chuck
2011 Sep 09
4
Very simple question about list components
I have a list 'ans' from the following code:
tt <- rnorm(50)
rr <- rnorm(50)
ans <- lm(rr~tt)
ans[1] is "$coefficients", ans[2] is "$residuals", ans[3] is
"$effects", ... and so on up to ans[12]. Is there an easy way to
display just these names and not the data they contain? I thought I
saw my advisor type "ans$" and they were displayed,
2008 Apr 08
1
Weibull maximum likelihood estimates for censored data
Hello!
I have a matrix with data and a column indicating whether it is censored
or not. Is there a way to apply weibull and exponential maximum
likelihood estimation directly on the censored data, like in the paper:
Backtesting Value-at-Risk: A Duration-Based Approach, P Chrisoffersen
and D Pelletier (October 2003) page 8?
The problem is that if I type out the code as below the likelihood
2008 Apr 15
1
by inconsistently strips class - with fix
summary:
The function 'by' inconsistently strips class from the data to which
it is applied.
quick reason:
tapply strips class when simplify is set to TRUE (the default) due to
the class stripping behaviour of unlist.
quick answer:
This can be fixed by invoking tapply with simplify=FALSE, or changing
tapply to use do.call(c instead of unlist
executable example:
2011 Oct 05
4
SPlus to R
I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator <-. Here are the first few lines of the S-Plus file:
sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8,
tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2),
2005 Jun 01
2
A suggestion to improve ifelse behaviour with vector yes/noarguments
> Thomas Lumley wrote:
> > On Tue, 31 May 2005, Duncan Murdoch wrote:
> >
> >
> >>M??kinen Jussi wrote:
> >>
> >>>Dear All,
> >>>
> >>>I luckily found the following feature (or problem) when tried to
> >>>apply
> >>>ifelse-function to an ordered data.
> >>>
> >>>
>
2009 Jun 18
1
lattice logaritmic scale (basis "e" ), rewriting labels using xscale.component
Hi there,
sorry for troubling everybody once again, I've got a problem rewriting
Sarkar's function for
rewriting the tick locations in a logaritmic way (s.
http://lmdvr.r-forge.r-project.org/code/Chapter08.R):
His example works for log 2 but I need log e (natural logarithm). My
problem is that if I replace
2 with "e" (using paste()), I get the error message that the location
2013 Feb 27
1
lattice xyplot point labelling
This is my reproducible example
tv.ms<-structure(list(inq = structure(4:17, .Label = c("D4", "D5", "D6a",
"D6b", "D6c", "D7", "D8", "F4", "F5a", "F5b", "F6a", "F6b", "F6c",
"F6d", "F7a", "F7b", "F8"), class =
2012 Nov 12
1
R lmer & SAS glimmix
Hi,
I am trying to fit a model with lmer in R and proc glimmix in SAS. I have
simplified my code but I am surprised to see I get different results from
the two softwares.
My R code is :
lmer(y~age_cat + (1|cat),data=fic,family=binomial(link = "logit"), NaGQ=1)
My SAS code is :
ods output Glimmix.Glimmix.ParameterEstimates=t_estimates;
proc glimmix data=tab_psi method=laplace;
2006 Aug 03
1
question about dll crashing R
I have ported some R code to C to make it faster.
I can perform .Call("foobar",....) once and it
works fine. Absolutely correct answer.
If I put a loop inside foobar and run the main code
routine more than 100 times, it crashes R.
Or if I call .Call("foobar"....) seperately more than
two tims it crashes R.
For the most part I am doing matirx multiplies using
EXP
2014 Jun 24
2
using C code to create data frame but always return as list
there is my code, expect return value is a data frame but R say it is list:
SEXP Julia_R_MD_NA_DataFrame(jl_value_t* Var)
{
SEXP ans,names,rownames;
char evalcmd[4096];
int i;
const char* dfname="DataFrameName0tmp";
jl_set_global(jl_main_module, jl_symbol(dfname), (jl_value_t*)Var);
//Get Frame cols
sprintf(evalcmd,"size(%s,2)",dfname);
jl_value_t*
2012 Aug 04
1
how to coerce the result of sweep to be an array if result of FUN is a string?
Hi,
I would like to use sweep to "sweep out" proportions and confidence intervals for an array, however when I supply a function which returns a string (containing something like "9% (3-18%)") I get back a list instead of an array, here is a simplified example:
# example showing that sweep does not return an array with same dimensions as STATS as advertised