Displaying 20 results from an estimated 10000 matches similar to: "appending an R-object to a list"
2010 Sep 05
3
appending to a list
Hi,
I've looked at previous discussions and did not get anything. I want to be
able to append to a list in a loop. Is this possible?
[[alternative HTML version deleted]]
2017 Jun 15
4
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi
I have a list :
mylist <- list( a = NULL, b = 1, c = 2 )
> mylist[1]
$a
NULL
> is.null(mylist[1])
[1] FALSE
> is.null(mylist$a)
[1] TRUE
why? I need to use mylist[1]
2008 Jul 20
4
drawing segments through points with pch=1
Please excuse me for asking such basic questions:
Here is my code
> y=c(1.21,0.51,0.14,1.62,-0.8,0.72,-1.71,0.84,0.02,-0.12)
> ybar=mean(y)
> ll=length(y);
> ybarv=rep(ybar,ll)
> x=1:ll
> plot(x,ybarv,pch=1)
> segments(x[1],ybar,x[ll],ybar)
What I get is a collection of small circles, with a segment "on top"
of the circles, which is almost what I want. But I
2009 Oct 25
3
NULL elements in lists ... a nightmare
I can define a list containing NULL elements:
> myList <- list("aaa",NULL,TRUE)
> names(myList) <- c("first","second","third")
> myList
$first
[1] "aaa"
$second
NULL
$third
[1] TRUE
> length(myList)
[1] 3
However, if I assign NULL to any of the list element then such
element is deleted from the list:
> myList$second <-
2013 Sep 02
1
Sweave: printing an underscore in the output from an R command
I am working with Sweave and would like to print out into my latex document the result of the R command
version$platform
So what I first tried in my .Rnw document was \Sexpr{print(version$platform)}.
However, the output from this command is the string "x86_64-apple-darwin10.8.0" (without the quotes). This contains an underscore, which is a special character in tex and so I get an error
2017 Jun 15
0
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi,
Try
> is.null(mylist[[1]])
[1] TRUE
Notice the double square brackets.
From: ?`[`
"The most important distinction between [, [[ and $ is that the [ can
select more than one element whereas the other two select a single
element."
On Thu, Jun 15, 2017 at 11:33 AM, ce <zadig_1 at excite.com> wrote:
> Hi
>
> I have a list :
>
> mylist <- list( a = NULL, b
2017 Jun 15
1
is.null(mylist[1]) and is.null(mylist$a) returns different values
I find that the str function is more helpful for understanding the difference between a null list and a list containing a null list than the implicit print function call that the interpreter invokes when you enter an expression at the console.
str( mylist[1] )
--
Sent from my phone. Please excuse my brevity.
On June 15, 2017 8:39:47 AM PDT, Huzefa Khalil <huzefa.khalil at umich.edu>
2008 Sep 10
4
re flecting a line
Suppose x and y are numeric vectors of the same length.
plot(x,y) #scatterplot
lmObj1 <- lm(y~x) # best fit line
abline(lmObj1) # good
lmObj2 <- lm(x~y) #get best fit but with axes interchanged
abline(lmObj2) # not what I want. I want the correct line, drawn on the same
graph, but with
# response and predictor variables interchanged
One way to proceed would be to
2012 Mar 21
2
list of matrices
Hello dear R-users,
I am currently trying to fill some datasatructure (array, list, hash...)
with matrices that are calculated by a function and do vary in size:
mylist = list()
for(i in 1:n)
mylist[i] = function(...) # returns a matrix
print(mylist[1]) # prints only the first element of the matrix
How can I store and afterwards access the matrices that are calculated
by my function?
2010 Apr 09
4
perhaps regular expression bug with | sign ??
Here is my interaction with R:
> sub(x='>|t|',pattern = '|t',replacement='zz')
[1] "zz>|t|"
So I say to myself "Clearly the | signs need to be escaped, so let's try
this"
> sub(x='>|t|',pattern = '\|t',replacement='zz')
[1] "zz>|t|"
Warning messages:
1: '\|' is an unrecognized escape in a
2009 Feb 05
2
eliminating control characters from formatted data files
I have a few hundred files of formatted data. Unfortunately most of them end
with a spurious CONTROL-Z. I want to rewrite the files without the spurious
character. Here's what I've come up with so far, but my code is unsafe
because it assumes without justification that the last row of df contains a
control character (and some NAs to fill up the record).
options(warn=-1) #turn off
2008 Jul 20
1
Error in edit(name,file,title,editor)
Can anyone help me with the following attempt to use an external
editor from within R
> vi(file="p286.R")
Error in edit(name, file, title, editor) : unable to open file to read
> edit(file="p286.R")
Error in edit(name, file, title, editor) : unable to open file to read
I have only recently re-started trying to learn R. (I tried before
but failed.)
I am working
2010 Apr 08
3
how does one print code
There is quite a long piece of code defining a certain function in one of the
R packages.
I think the code has a bug and I want to get the code into a file so that I
can take a proper look, and possibly fix it.
how does one do this? (I mean getting the code into a file, not fixing the
bug.) I suppose I could copy and paste, but that's a bit error prone for
various reasons. I want the same
2010 May 17
3
applying quantile to a list using values of another object as probs
Hi r-users,
I have a matrix B and a list of 3x3 matrices (mylist). I want to
calculate the quantiles in the list using each of the value of B as
probabilities.
The codes I wrote are:
B <- matrix (runif(12, 0, 1), 3, 4)
mylist <- lapply(mylist, function(x) {matrix (rnorm(9), 3, 3)})
for (i in 1:length(B))
{
quant <- lapply (mylist, quantile, probs=B[i])
}
But quant
2007 Oct 20
1
Getting at what a named object represents in a function...
Hi,
I'm pretty new to R.
I have an object (say a list) and I I have a function that I call on
various columns in that list (excuse terminology if it's wrong/ambiguous).
Imagine its like this (actual values are unimportant) and called mylist:
>mylist
A B
1 5
2 5
3 6 4 8
5 0
I have a function:
foo = function(param){
#modify list A or B values depending on
2011 Mar 21
1
Sweave, white space and code blocks
Sweave is very useful, and I'm gradually getting used to it.
I've just been battling Sweave over the re-use of code chunks. As I am
pretty ignorant in the byways of both Sweave and R, this took a chunk of
time to sort out. Here is what I learned:
If one re-uses a code chunk, then Sweave (but not Stangle) will insist that
<>
start in column 1. In particular, white space to its left
2011 Apr 16
1
Sweave, SweaveHooks and printing the label
I would like to print the label of each code chunk, just before printing the
code chunk itself. Is that possible using SweaveHooks, or by some other
mechanism?
Thanks
David
--
View this message in context: http://r.789695.n4.nabble.com/Sweave-SweaveHooks-and-printing-the-label-tp3453829p3453829.html
Sent from the R help mailing list archive at Nabble.com.
2011 Mar 24
1
Storing user-defined R functions
Hello, I don't want to find out how to make packages unless that becomes
necessary. Also, I don't want to clog up the computer memory with functions
that I'm not using. (It would be great if someone in this forum would
explain how memory is used when I type library(MASS) and then use only one
function from MASS. Are all the many MASS functions then residing in memory,
or only the one I
2008 Oct 22
1
getting the "name" of an object
Hello,
I'm looking for a way to get the "name" of an object when it is used
within an "sapply".
More precisely, with a simple example :
I have a named list of objects :
myList = list(a=rnorm(10),b=rnorm(10),c=rnorm(10))
I would like to create a new object from each of the components of
myList using the "sapply" function, for example to get the mean of all
2009 Feb 02
3
Environmental variables
I use a Mac (10.4.11 Mac Os X).
In my .tcshrc I define an environmental variable MY.
Is it possible to find out its value from inside R? When one loads
R for Mac OS X Cocoa GUI written by:
Simon Urbanek
Stefano M. Iacus
are files like .tcshrc read by R?
Can I make the value of this environmental variable available to R?
Sys.getenv() produces a lot of output, with the values of many