Displaying 20 results from an estimated 4000 matches similar to: "Transfering data from R list to other document format"
2007 May 16
2
substitute "x" for "pattern" in a list, while preservign list "structure". lapply, gsub, list...?
I am experimenting with some of the common r functions.
I had a question re:using "gsub" (or some similar functions) on the contents of a list.
I want to design a function that looks at "everything" contained din a list, and anytime it finds the text string "pattern" replace it with "x". I also wish to preserve the "structure" of the original
2010 Feb 26
3
Preserving lists in a function
Dear R users,
A co-worker and I are writing a function to facilitate graph plotting in R. The function makes use of a lot of lists in its defaults.
However, we discovered that R does not necessarily preserve the defaults if we were to input them in the form of list() when initializing the function. For example, if you feed the function codes below into R:
myfunction=function(
list1=list
2017 Dec 04
2
Dynamic reference, right-hand side of function
:-)
I don't insist on anything, I'm just struggling to learn a new language and partly a new way of thinking, and I really appreciate the corrections. I hope I someday will be able to handle lists in R as easy as I handle loops in Stata...
Thanks again!
Love
-----Ursprungligt meddelande-----
Fr?n: peter dalgaard [mailto:pdalgd at gmail.com]
Skickat: den 4 december 2017 23:09
Till:
2007 Jun 28
3
Function call within a function.
I am trying to call a funtion within another function
and I clearly am misunderstanding what I should do.
Below is a simple example.
I know lstfun works on its own but I cannot seem to
figure out how to get it to work within ukn. Basically
I need to create the variable "nts". I have probably
missed something simple in the Intro or FAQ.
Any help would be much appreciated.
EXAMPLE
2009 Oct 30
2
Names of list members in a plot using sapply
Hi R users:
I got this code to generate a graphic for each member of a lists.
list1<-list(A=data.frame(x=c(1,2),y=c(5,6)),B=data.frame(x=c(8,9),y=c(12,6)))
names1<-names(list1)
sapply(1:length(list1),function(i)
with(list1[[i]],plot(x,y,type="l",main=paste("Graphic of",names1[i]))))
Is there a more elegant solution for not to use two separate lists?
I would like to
2010 Mar 15
1
rbind, data.frame, classes
Hi,
This has bugged me for a bit. First question is how to keep classes with
rbind, and second question is how to properly return vecotrs instead of
lists after turning an rbind of lists into a data.frame
list1=list(a=2, b=as.Date("20090102", format="%Y%m%d"))
list2=list(a=2, b=as.Date("20090102", format="%Y%m%d"))
rbind(list1, list2) #this loses the
2013 Jan 10
1
merging command
HI Eliza,
You could do this:
set.seed(15)
mat1<-matrix(sample(1:800,124*12,replace=TRUE),nrow=12) # smaller dataset
#Your codes
?list1<-list()
?for(i in 1:ncol(mat1)){
? list1[[i]]<-t(apply(mat1,1,function(x) x[i]-x))
? list1}
?x<-list1??
x<-matrix(unlist(x),nrow=12)
x<-abs(x)
?y<-colSums(x, na.rm=FALSE)
z<-matrix(y,ncol=10)
?z<-as.dist(z)
?z
?# ?? 1?? 2?? 3?? 4?? 5??
2007 Oct 15
1
The "condition has length > 1" issue for lists
I have the following code:
list1 <- list()
for (i in list.files(pattern="filename1")){
x <- read.table(i)
list1[[i]] <- x
}
list2 <- list()
for (i in list.files(pattern="filename2*")){
x <- read.table(i)
list2[[i]] <- x
}
anslist <- vector('list', length(list1))
for(i in 1:length(list1))
if (list1[[i]] & list2[[i]] >1)
2011 Jan 20
1
syntax for a list of components from a list
I'm attempting to generalise a function that reads individual list components, in this case they are matrices, and converts them into 3 dimensional array. I can input each matrix individually, but want to do it for about 1,000 of them ...
This works
array2 <- abind(list1[[1]],list1[[2]],list1[[3]],along=3)
This doesn't
array2 <- abind(list1[[1:3]],along=3)
This doesn't either
2011 Nov 21
1
Creating a list from all combinations of two lists
R-helpers:
Say I have two lists of arbitrary elements, e.g.:
list1=list(c(1:3),"R is fun!",c(3:6))
list2=list(c(10:5),c(5:3),c(13,5),"I am so confused")
I would like to produce a single new list that is composed of all
combinations of the "top level" of list1 and list2, e.g.:
listcombo=list(list(list1[[1]],list2[[1]]),list(list1[[1]],list2[[2]]
2011 Feb 06
1
Applying 'cbind/rbind' among different list object
Hi, I am wondering whether we can apply 'cbind/rbind' on many **equivalent**
list objects. For example please consider following:
> list1 <- list2 <- vector("list", length=2); names(list1) <- names(list2)
<- c("a", "b")
> list1[[1]] <- matrix(1:25, 5)
> list1[[2]] <- matrix(2:26, 5)
> list2[[1]] <- 10:14
> list2[[2]] <-
2012 Apr 19
1
question about lists
I am new to R, and I have been running into the following situation
when I mistype a variable name in some code:
> list1 <- list( a=1, b=2 )
> list2 <- list( a=1 )
> list2$b <- list1$c
> list2
$a
[1] 1
I would think at the point where I am trying to reference a field
called "c" -- that does not exist -- in list1, there would be an error
flagged.
Instead, list1$c
2011 Feb 08
2
Extrcat selected rows from a list
Hi,
I have two lists
1) List1- 30,000 rows and 104 columns
2) List2- a list of 14000 selected rownames from List 1
Now, I want to extract all the 104 columns of List1 matching with the 14000 selected rownames from List2.
Psedocode will be something like this:
match rownames(List2) with rownames(List1)
extract selected matched 104 coloumns from (List1)
strore in-> List3
So the
2004 Jan 24
1
loop variable passage and lists
I cannot understand why the following expression is accepted (and gives the expected result: to set column 3 and 4 of the first
element of list1 -a data.frame list- as first element of list2):
> list2[[1]]<-list1[[1]][3:4]
...while this one is not (to do the same iteratively from the first to the eleventh element of list1):
> for (i in 1:11){list2[[i]]<-list1[[i]][3:4]}
Error in
2004 Oct 25
1
usage and behavior of 'setIs'
Hello,
am I using 'setIs' in the correct way in the subsequent (artifical) example?
Do I have to specify explicit 'setAs' for 'list' and 'vector' or
should this work automatically, since "getClass("List1")" states
an explicit coerce also for these classes.
I'm working with R 2.0.0 Patched (2004-10-06) on windows 2000.
Thanks for your
2011 Jan 08
3
Question on list objects
Hi, I have 2 questions on list object:
1. Suppose I have a matrix like:
dat <- matrix(1:9,3)
Now I want to replicate this entire matrix 3 times and put entire result in a list object. Means, if "res" is the resulting list then I should have:
res[[1]]=dat, res[[2]]=dat, res[[3]]=dat
How can I do that in the easilest manner?
2. Suppose I have 2 list objects:
list1 <- list2
2017 Dec 04
0
Dynamic reference, right-hand side of function
Loops are not evil, and no-one in this thread said they are. But I
believe your failure to provide a reproducible example is creating
confusion, since you may be using words that mean one thing to you and
something else to the readers here.
################################
# A reproducible example includes a tiny set of sample data
# Since we cannot reproducibly refer to filenames (your
2020 Aug 14
2
Another possible tracing feature for TableGen
I hacked around a bit with the simple case of tracing just classes and defs (no multiclasses or defms). Below you will see my test file and then the output produced. Note that the regular output from the PrintRecords backend follows the trace, so you can see the final classes and records there. Once the trace can be selective, it makes sense to add another option for PrintRecords that restricts
2007 Oct 13
1
Controlling values in read.table
I have this code:
list1 <- list()
for (i in list.files(pattern=".*c02.*AFDH0.*")){
x <- read.table(i,skip=20,fill=TRUE)
list1[[i]] <- x
}
Somehow I would like the read.table function to read only values in each
file that are over a certain limit, say >1. Is this the easiest way or is it
better to tamper with 'list1' when it's done?
--
View this message in
2008 Nov 17
2
re sults from "do.call" function
Dear R users...
I made this by help of one of R users.
_________________________________________________________________
X=matrix(seq(1,4), 2 , 2)
B=matrix(c(0.6,1.0,2.5,1.5) , 2 , 2)
func <- function(i,y0,j) { y0*exp(X[i,]%*%B[,j]) }
list1 <- expand.grid( i=c(1,2) , y0=c(1,2) , j=c(1,2) )
results <- do.call( func , list1 )