Displaying 20 results from an estimated 9000 matches similar to: "Selecting first 7 elements"
2010 Nov 08
7
How to rbind list of vectors with unequal vector lengths?
Hi,
How to rbind these vectors from a list?:
> l <- list(a = c(1, 2), b = c(1, 2, 3))
> l
$a
[1] 1 2
$b
[1] 1 2 3
> do.call(rbind, l)
[,1] [,2] [,3]
a 1 2 1
b 1 2 3
Warning message:
In function (..., deparse.level = 1) :
number of columns of result is not a multiple of vector length (arg 1)
>
-J
2010 May 23
4
creating a reverse geometric sequence
Hello,
Can anyone think of a non-iterative way to generate a decreasing geometric
sequence in R?
For example, for a hypothetical function dg, I would like:
> dg(20)
[1] 20 10 5 2 1
where I am using integer division by 2 to get each subsequent value in the
sequence.
There is of course:
dg <- function(x) {
res <- integer()
while(x >= 1) {
res <- c(res, x)
x
2009 Feb 27
3
question about 3-d plot
Hi R Users,
I have produced a simulated scatter plot of y versus x tightly clustered
around the 45 degree line through the origin with the following code:
x <- seq(1,100)
y <- x+rnorm(100,0,10)
plot(x,y,col="blue")
abline(0,1)
Is there some way to generate a 3-dimensional analogue of this? Can I get a
similar simulated scatter plot of points in 3 dimensions where the points
2009 Mar 09
2
mean reverting model
dear useRs,
i'm working with a mean reverting model of the following specification:
y = mu + beta(x - mu) + errorterm, where mu is a constant
currently I estimate just y = x (with lm()) to get beta and then
calculate mu = estimated intercept / (1-beta).
but I'd like to estimate mu and beta together in one regression-step
and also get the test-statistics (including parameter
2010 Jul 06
3
Function for gruping similar variables?
Hi,
I have a matrix of results of multiple 2x2 chi^2 tests, non-
significant tests are marked as TRUE. Is there a function for grouping
those variables in a similar way LSD.test from agricolae library does?
I reviewed LSD.test's source but it's not helpful for me.
This is my matrix:
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
1 TRUE FALSE TRUE TRUE TRUE FALSE TRUE
2 FALSE TRUE
2010 Sep 18
3
How to check the available of a package on R repo
Hi folks,
Debian 504 64-bit
What is the correct syntax to check the available of a package on R repo?
> available.packages("emacs", "OS_type=linux")
Warning: unable to access index for repository emacs
Package Version Priority Depends Imports LinkingTo Suggests Enhances
OS_type License File Repository
> available.packages("emacs")
Warning: unable
2010 Apr 30
3
replace elements in a list
Dear all, I have a list like this: l <- list(list(a=1,b=NULL), list(a=2,b=2))
I want to find out the elements with value of NULL and replace them with NA.
The actual case has a very long list, so manually find out and replace
them is not an option.
I can use for loop to do this, but I want to know if there is
vectorized way (or other ways) to do it?
Thanks
--
Wincent Rong-gui HUANG
Doctoral
2009 Jun 08
2
Tinn R
Dear R-users,
I have installed the latest version of Tinn R (Version 2.2.0.2).
With the older versions it was possible to run Tinn R next to R and then select code that one could send to R.
Now it seems that one has to start the R gui in Tinn R and then it is possible to select en run code of R.
But if I start R within Tinn R it does NOT start the R-Gui but only the R console. When I start R
2008 Dec 10
2
missing argument
Dear list,
I have a question and I'm going to give an example of my problem
f<- function(d1, d2, d3)
{
d<- d1*d2/d3
return(d)
}
v1<- 1
v2<- 2
If I try
f(v1, v2, v3)
Error in f(v1, v2, v3) : object "v3" not found
I obviously got the above error message.
I would like to add something to my function to allow me to get a certain
value (say zero)
if one of the arguments is
2011 May 24
2
Extracting day of month from Date objects
I've always found the chron library to be useful for
tasks like this:
> x <- round(runif(10)*100000, digits=0)
> y <- as.Date(x, origin="1970-01-01")
> library(chron)
> days(y)
[1] 7 25 26 25 10 24 1 31 12 8
31 Levels: 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < ... < 31
Notice that it returns the days as
2010 Aug 11
4
Arbitrary number of covariates in a formula
Hello!
I have something like this:
test1 <- data.frame(intx=c(4,3,1,1,2,2,3),
status=c(1,1,1,0,1,1,0),
x1=c(0,2,1,1,1,0,0),
x2=c(1,1,0,0,2,2,0),
sex=c(0,0,0,0,1,1,1))
and I can easily fit a cox model:
library(survival)
coxph(Surv(intx,status) ~ x1 + x2 + strata(sex),test1)
However, I want to
2009 May 08
3
'Dynamic' 3D plot
Hi,
I am looking for a R package to draw 3d plot. But not in a static way like scatterplot3d or stuff like that. I would like to make rotate the plot, to zoom/unzoom etc..., actually to render the graph 'dynamic'... (for the biologist and bioinformatician, a R package which permitts to reproduce what pdb viewer does).
Does a Way exist to do something like that in R ?
Thanks,
2008 Dec 15
5
how to create duplicated ID in multi-records per subject dataset
Hi R helpers,
If I have a dataset looks like:
ID record
1 20
. 30
. 25
2 26
. 15
3 21
4.....................
And I want it becomes
ID record
1 20
1 30
1 25
2 26
2 15
3 21
4.....................
That is, I have to duplicate IDs for those with multiple records. I am wondering it is possible to be
2010 Oct 25
2
Question on passing the subset argument to an lm wrapper
Hello,
How would you go about handling the following situation?
This is on R 2.12.0 on Ubuntu 32-bit.
I have a wrapper function to lm. I want to pass in a
subset argument. First, I just thought I'd use "...".
## make example reproducible
set.seed(123)
df1 <- data.frame(age = rnorm(100, 50, 10),
bmi = rnorm(100, 30, sd = 2))
## create a wrapper using
2010 Feb 16
3
Keyboard
All,
I installed R-2.10.1 with Readline=no. Now for some reason R does not recognize some key strokes like the directional arrows.
I am not sure if Readline is the problem or not.
I have tried .Cofigure with Readline = yes but it doesn't fix the problem nor do I really know if readline is the problem to start with.
Has anybody else run into similar problems?
Thanks,
Steve
[[alternative
2010 Oct 05
4
R editor in ubuntu!
Hello R-Users!
I am looking for an editor to be able to execute commands into R in Linux ubuntu. Is there any suggestion?
Thanks.
[[alternative HTML version deleted]]
2010 Jun 16
3
Function argument as string
Hi,
Suppose a write a function
a_fn<-function(arg1)
{
return(table(arg1));
}
I have a column called AGE. Now I call the function c = a_fn(AGE);
When a_fn is called, AGE is received in arg1. My question is, how do I
access the actual name of the argument arg1? i.e, inside the
function, i need to know that the actual name of arg1 is "AGE" in this
case.
Thanks in advance,
2011 Aug 29
2
rpart: apply tree to new data to get "counts"
Hi,
when I have made a decision tree with rpart, is it possible to "apply"
this tree to a new set of data in order to find out the distribution
of observations? Ideally I would like to plot my original tree, with
the counts (at each node) of the new data.
Reagards,
Jay
2011 Mar 23
3
Compare three or more values?
Is there a less cryptic way to compare three or more values?
allTheSame<-c("red","red","red","red")
notAllTheSame<-c(132,132,132,999)
all.identical <- function(vectorToTest){
cIdentical=sum(vectorToTest %in% vectorToTest[1])
return(cIdentical==length(vectorToTest))
}
all.identical(allTheSame)
all.identical(notAllTheSame)
Thanks in
2009 Dec 06
5
optim with constraints
Hi, dear R users
I am a newbie in R and I wantto use the method of meximum likelihood
to fit a Weibull distribution to my survival data. I use "optim" as
follows:
optim(c(1, 0.25),weibull.like,mydata=mydata,method="L-BFGS-B",hessian
= TRUE)
My question is: how do I setup the constraints so that the two
parametrs of Weibull to be pisotive? Or should I use other function