Displaying 20 results from an estimated 40000 matches similar to: "apply on two lists?"
2009 Dec 01
2
go back a block of code in history
Suppose I run the following code in the R session. At the last prompt
'>', I want to retrieve the second command (staring with 'y'). But I
have to type up arrow many times, which is very inconvenient. I'm
wondering if there is a way to configure R to skip block of code in
the history?
> x=list(a=c(1,2),b=c(3,4,5))
> y=list(a=c(1,2),b=c(3,4,5))
> lapply(seq(along=x)
2009 Dec 01
2
go back a block of code in history
Suppose I run the following code in the R session. At the last prompt
'>', I want to retrieve the second command (staring with 'y'). But I
have to type up arrow many times, which is very inconvenient. I'm
wondering if there is a way to configure R to skip block of code in
the history?
> x=list(a=c(1,2),b=c(3,4,5))
> y=list(a=c(1,2),b=c(3,4,5))
> lapply(seq(along=x)
2009 Nov 19
4
Is there an variant of apply() that does not return anything?
There are a few version of apply() (e.g., lapply(), sapply()). I'm
wondering if there is one that does not return anything but just
silently apply a function to the list argument.
For example, the plot function is applied to each element in 'alist'.
It is redundant to return anything from apply.
apply(alist,function(x){ plot each element of alist})
2009 Aug 11
3
Is there a summary on different version of 'apply' functions? What is the meaning of the prefixes?
Hi,
There are quiet a few different 'apply' functions, such as lapply,
sapply and many more. I'm very familiar with the 'Apply' function in
Mathematica. Can somebody point me a summary of all the 'apply'
functions in R. Also, I'm curious that what 'l' and 's' (and other
prefixes) stand for in 'lapply' and 'sapply'
Regards,
Peng
2009 Sep 05
2
How to 'apply' on multiple arguments?
Hi,
I am wonder if there is a function similar 'apply' but it could accept
multiple arguments?
For example, I have the following matrix.
x=matrix(1:6,nr=2)
y=matrix(1:6,nr=2)
I want to find a function that can be used to compute the linear
regression for each pair of rows in the two matrices?
multiple_apply(x,y,1,function(u,v){lm(u ~ v)}
That is, I wound like something like the above
2009 Oct 24
1
How apply a function to a list while maintaining list name?
I use lapply to apply a function to the list 'L'. But of course, the
list names in 'X' is not maintained. I'm wondering if there is a
function that can maintain the list names as well as apply the
function.
$ Rscript lapply.R
> L=list(x=c('a','b'), y=c('a','b'))
> L
$x
[1] "a" "b"
$y
[1] "a" "b"
2009 Nov 03
3
How to exclude certain columns by column names?
I can exclude columns by column number using '-'. But I wondering if
there is an easy way to exclude some columns by column names.
> x=cbind(c(1,2),c(3,4))
> x
[,1] [,2]
[1,] 1 3
[2,] 2 4
> colnames(x)=c('a','b')
> x
a b
[1,] 1 3
[2,] 2 4
> x[,-'a']
Error in -"a" : invalid argument to unary operator
> x[,-1]
[1] 3 4
2009 Dec 10
3
How to figure out which the version of split is used?
There are a number of functions that are dispatched to from split().
> methods('split')
[1] split.data.frame split.Date split.default split.POSIXct
Is there a way to figure out which of these variants is actually
dispatched to when I call split? I know that if the argument is of the
type data.frame, split.data.frame will be called? Is it the case that
if the argument is not
2009 Dec 11
1
How to get rid of NULL in the result of apply()?
The following code returns a list with the 2nd element as NULL. I'm
wondering what the best way to get rid of NULL element in an
'apply()'s result.
> lapply(1:3, function(x) {
+ if(x==2) {
+ return(NULL)
+ } else {
+ return(x)
+ }
+ }
+ )
[[1]]
[1] 1
[[2]]
NULL
[[3]]
[1] 3
2009 Aug 10
5
Example scripts for R Manual
Hi,
I am wondering if some experienced users would help put the
ready-to-run code of the examples in the manuals. It would help new
users learn R faster by putting all the examples in an ready-to-run R
script file. Can somebody help do so sometime and post the code along
with the pdf manuals?
http://cran.r-project.org/manuals.html
Regards,
Peng
2010 Feb 03
5
How to export the examples in help(something) to a file?
Some examples in the help page are too long to be copied from screen.
Could somebody let me know some easy way on how to extract the example
to a file so that I can play with them?
2009 Sep 04
2
How to join two matrices?
Hi,
Suppose I have the following two matrices.
> x=matrix(1:4,nr=2)
> y=matrix(5:8,nr=2)
I want to join the two matrices to get the following two new matrices.
I did a search but I don't find any relevant webpage. Can somebody let
me know how to do it?
[,1] [,2]
[1,] 1 3
[2,] 2 4
[3,] 5 7
[4,] 6 8
[,1] [,2] [,3] [,4]
[1,] 1 3 5 7
[2,]
2009 Dec 18
4
How to print to file?
I don't find a function to print a string to file. Would somebody let
me know what function I should use?
2009 Oct 29
3
Weird error: Error in xj[i] : invalid subscript type 'list'
I got the error. I haven't been able to get a stand along case so that
I can show it here. But could somebody give some clue on what could
cause this error? Since I never defined xj[i], I don't understand
where this error come from.
Error in xj[i] : invalid subscript type 'list'
2012 Dec 30
4
[LLVMdev] git repository of the tutorial
Hi,
I'm learning the tutorial.
http://llvm.org/docs/tutorial/
I'm wondering if there is already a git repository of the examples in
the tutorial so that I don't have to copy the code from the webpage.
Thanks!
--
Regards,
Peng
2010 Jan 21
3
Anova unequal variance
I found this paper on ANOVA on unequal error variance. Has this be
incorporated to any R package? Is there any textbook that discuss the
problem of ANOVA on unequal error variance in general?
http://www.jstor.org/stable/2532947?cookieSet=1
2009 Aug 06
5
Is there a 'vi' mode in R?
Hi,
I'm wondering if R provide a vi mode in the command line just like
other shells such as bash do. Can somebody let me know?
Regards,
Peng
2009 Sep 14
3
How to refer to the last a few rows?
Hi,
x=matrix(1:60,nr=6)
I can refer the last 2 rows by
x[5:6,]
If I don't know the total number of rows is 6, is there a way to refer
the last 2 rows?
Regards,
Peng
2010 Jan 01
5
How to not to terminate read.table if the input file is empty?
read.table terminates the program if the input file is empty. Is there
way to let the program continue and return me a NULL instead of
terminating the program?
$ Rscript read_empty.R
> read.table("empty_data.txt")
Error in read.table("empty_data.txt") : no lines available in input
Execution halted
$ cat read_empty.R
read.table("empty_data.txt")
$ cat
2009 Oct 02
3
How to get duplicated items in a vector?
Hi,
> x=c(rep(1,3),rep(3,2))
> x
[1] 1 1 1 3 3
> duplicated(x)
[1] FALSE TRUE TRUE FALSE TRUE
>
As shown in the above code, 'duplicated' doesn't return 'F' for the
first '1' and first '3' in 'x'. I am wondering if there is a function
that can return an indicator for any element whether it appears in a
vector twice or more.
Regards,
Peng