Displaying 20 results from an estimated 20000 matches similar to: "How to rbind list of vectors with unequal vector lengths?"
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
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 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,
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
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
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]]
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
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 14
4
Feature Request: Multiline Comments
Hello,
Is it possible to extend the R lexer/parser to include multiline comments like
/*
acomment
*/
?
This way I can integrate emacs org-mode with my R code, so that I can
have a table of contents,
section folding, html-output of source etc.
e.g
/*
* Display Code
*/
#+BEGIN_SRC R
foo <- function(...){
stuff
}
#+end_src
and so on .
Thanks
Saptarshi
2010 Jul 16
4
how to comment off sections
Hello,
Is there an way to easy comment of sections of code? I was thinking
something along the lines of
\dontrun{
codeline 1
....
codeline k
}
but that could be used in regular script files. When I am still
working on a script, I often want to being using what is done, but I
would like the parts I am still working on not to be run when I use
source() on the file. I can set everything off
2011 May 04
3
SAPPLY function XXXX
Hello everyone,
I am attempting to write a function to count the number of non-missing
values of each column in a data frame using the sapply function. I have the
following code which is receiving the error message below.
> n.valid<-sapply(data1,sum(!is.na))
Error in !is.na : invalid argument type
Ultimately, I would like for this to be 1 conponent in a larger function
that will produce
2010 Aug 21
3
problems with merge() - the output has many repeated lines
Hi everyone,
I have been merging many big dataframes (about 80000 rows
each) and I never had this problem, but now it happened to
me and I want to know if someone knows what could be
happening.
The final dataframe has many rows, an impossible number! I
have done edit(dataframe) and I saw that there are many
repeated rows (all equal).
Thanks for any help,
Cec?lia Carmo
Universidade de
2010 Jun 15
3
How to see how a function is written
Hello,
If I want to see how, say, apply function is written, how would I be
able to do that?
Just typing "apply" at the prompt does not work.
Thank you for help!
Sergey
2007 Mar 05
3
Rbind with data frames -- column names question
As part of my work, I am trying to append matrices onto data frames.
Naively I assumed that when rbinding a data.frame and matrix, the matrix
would be coerced and appended, keeping the names from the data frame.
Clearly, I am not fully understanding the process by which rbind works.
Example code:
> A<-data.frame(1,1,1); names(A)=letters[1:3] ; B<-matrix(0,2,3)
> rbind(A,B)
2010 Aug 07
4
basic question about t-test with adjusted p value
I have read the R manual and help archives, sorry but I'm still stuck.
How would I do a t-test with an adjusted p-value?
Suppose that I use t.test ( ) , with the function argument alternative =
"two.sided", and data such that degrees of freedom = 20. The function
calculates a t-statistic of 2.086, and p-value =0.05
How do I then adjust the p-value? My thought is to do
2010 Feb 17
8
Use of R in clinical trials
Dear all,
There have been a variety of discussions on the R list regarding the use of R in clinical trials. The following post from the STATA list provides an interesting opinion regarding why SAS remains so popular in this arena: http://www.stata.com/statalist/archive/2008-01/msg00098.html
Regards,
-Cody Hamilton
2008 Apr 22
3
how to read in multiple files with unequal number of columns
Dear all,
I want to read in 1000 files which contain varying number of columns.
For example:
file[1] contains 8 columns (mixture of characters and numbers)
file[2] contains 16 columns etc
I'm reading everything into one big data frame and when I try rbind, R
returns an error of
"Error in rbind(deparse.level, ...) :
numbers of columns of arguments do not match"
Below is my
2010 May 23
3
Selecting first 7 elements
Hi,
I have a list of 100, each list has 20 elements, and I would like to
select the first 7 elements in each list.
Let's take the alphabet as an example.
x <- lapply(1:100, function(i) sample(LETTERS))
I tried x[[1:7]], but it doesn't work. Can anyone enlighten me on how
to do such selections?
Thank you.
Kang Min
2007 Dec 11
2
range( <dates>, na.rm = TRUE ) (PR#10508)
(Drats! Jitterbug is playing tricks with the PR# again. Attempting to
refile so that we can kill PR#10509)
Peter Dalgaard wrote:
> Kurt.Hornik at wu-wien.ac.at wrote:
> =20
>> ------- Start of forwarded message -------
>> Date: Tue, 13 Nov 2007 21:44:57 +0100
>> To: Steve Mongin <sjm at ccbr.umn.edu>
>> Cc: cran at r-project.org
>> Subject: Re: range(