similar to: Accessing elements of a list

Displaying 20 results from an estimated 10000 matches similar to: "Accessing elements of a list"

2011 Mar 01
2
Does POSIXlt extract date components properly?
I would like to use POSIX classes to store dates and extract components of dates. Following the example in Spector ("Data Manipulation in R"), I create a date > mydate = as. POSIXlt('2005-4-19 7:01:00') I then successfully extract the day with the command > mydate$day [1] 19 But when I try to extract the month > mydate$mon [1] 3 it returns the wrong month. And
2010 Mar 15
1
Eliminate border in wireframe plot
How can I eliminate the border drawn by default around a wireframe plot? I've tried using border=NA and box=FALSE to no avail. Scott Waichler Pacific Northwest National Laboratory scott.waichler at pnl.gov
2009 Dec 29
4
subsetting by groups, with conditions
I have a data set similar to this: P1id Veg1 Veg2 AreaPoly2 P2ID 1 p p 1 1 1 p p 1.5 2 2 p p 2 3 2 p h 3.5 4 For each group of "Poly1id" records, I wish to output (subset) the record which has largest "AreaPoly2" value, but only if
2010 Mar 05
4
conditioning variable in panel.xyplot?
I wish to create a multipanel plot (map) from several datasets ("d" and "q" in the example below). I can condition the main xyplot statement on the "site" variable, but I don't know how to pass a conditioning variable to panel.xyplot plot so that the x-y coordinates from dataset q are only plotted at the appropriate site. library(lattice) d <-
2010 Jun 22
2
Lattice legend
I have a moderately complex graph with three panels. There are data points plotted, and fitted lines are added using a panel function, which includes "with(alt.data[[which.packet()[1]]]" statements. It all graphs out beautifully, but none of the usual tricks to get the proper legend to plot are working, i.e., using auto.key, key, etc. One message I keep getting is Error in
2011 May 04
1
adding columns to dataframes contained in a list
hi there, I have a list of 5 identical dataframes: mydf <- data.frame(x=c(1:5), y=c(21:25)) mylist <- rep(list(mydf),5) and a factor variable with 5 levels: foo <- c(letters[1:5]) foo <- as.factor(foo) Question: I'd like to add a new variable to each dataframe in the list, each containing only one level of the factor variable. So mylist[[1]] should have a new variable z
2008 Mar 13
3
Splitting a set of vectors in a list
I have a set of character vectors of uneven length that I have stored in a list. I can easily enough get any column of them using lapply but what I want is to be able to create a matrix of them. Other than some kind of brute force looping approach I have drawn a blank. Would somebody please suggest something? Thanks Example. mylist <- list(aa=c("cat","peach" ),
2012 Jun 28
3
loop through and modify multiple data frames
Hi Newbie question: I have a set of data frames that I want to do the same calculations on each. I've found out that I can put them in a list and loop through the list to do the calculation, but not put the results back into each data.frame.. For example three data frames cats, dogs, birds where >cats name eats_kg 1 bob 3 2 garfield 4 3 chuck 6 and dogs and birds are similar but not
2007 Dec 13
2
Overlaying trellis xyplot on contourplot
Friends: I wish to overlay data points on a contour graph. The following example produces a nice contour plot, but I have not mastered the concept of using panel functions to modify plots. Can someone show me how to overlay the data points (given after contour plot statement) on the contourplot? --Seth model <- function(a,b,c,X1,X2) # provide model function for contour
2009 Sep 18
1
xyplot: Can I identify groups but not use them for regression?
I wish to identify groups representing different treatments, but to plot them and do a regression using a continuous variable ("cover") ignoring the groupings. d$year <- NA d$year <-c(rep(2007,12), rep(2008,12)) d$treatment <- c(rep("A",4),rep("B",4),rep("C",4), rep("A",4), rep("B",4), rep("C",4)) d$cover <-
2010 Sep 21
1
Doing operations by grouping variable
I'm writing an expression that requires searching a vector according to group. As an example, I want to find the maximum value in each of 5 groups. group=rep(1:5, each=5) # create grouping variable variable=rnorm(25) # generate data d <- data.frame(group,variable) # make data frame
2012 Mar 23
1
Remove wireframe outer box but keep ticks
I would like to eliminate the outer box around a lattice wireframe graph, but the usual recommended solution, which is to assign a color of 'transparent' to the axis.line parameter, eliminates ticks if the 'arrows=F' command is used, as shown in the following example: test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + test[,2] test = cbind(test, z) names(test) =
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 <-
2010 Jun 08
3
more dates and data frames
Dear R People: So thanks to your help, I have the following: > dog3.df <- read.delim("c:/Users/erin/Documents/dog1.txt",header=FALSE,sep="\t") > dog3.df V1 V2 1 1/1/2000 dog 2 1/1/2000 cat 3 1/1/2000 tree 4 1/1/2000 dog 5 1/2/2000 cat 6 1/2/2000 cat 7 1/2/2000 cat 8 1/2/2000 tree 9 1/3/2000 dog 10 1/3/2000 tree 11 1/6/2000 dog 12 1/6/2000
2010 Jul 27
2
Sum list elements
Hi! I have a list of 24 elements, all of the same type (dataframe, for example). I am looking for an alternative to mylist[[1]] + mylist[[2]] + ... + mylist[[24]] to obtain the sum. Anyone can help me? Thanks in advance. Nicola S. [[alternative HTML version deleted]]
2013 Feb 12
3
grabbing from elements of a list without a loop
Hello! # I have a list with several data frames: mylist<-list(data.frame(a=1:2,b=2:3), data.frame(a=3:4,b=5:6),data.frame(a=7:8,b=9:10)) (mylist) # I want to grab only one specific column from each list element neededcolumns<-c(1,2,0) # number of the column I need from each element of the list # Below, I am doing it using a loop: newlist<-NULL for(i in 1:length(mylist) ) {
2013 Apr 29
3
rbinding some elements from a list and obtain another list
Hi everybody, I have a list, where every element of this list is a data frame. An example: Mylist<-list(A=data.frame, B=data.frame, C=data.frame, D=data.frame) I want to rbind some elements of this list. As an example: Output<-list(AB=data.frame, CD=data.frame) Where AB=rbind(A,B) CD=rbind(C,D) I’ve tried: f<-function(x){ for (i in
2010 Apr 05
1
Deleting many list elements in one time
Hi guys, here is a simple thing I want to do but it doesn't work: I have a vector of the element indexes that I want to delete called index so when I write myList[[index]] <- NULL to delete these elements here is what I get: Error in myList[[index]] <- NULL : more elements supplied than there are to replace Isn't it possible to delete multiple elements? ----- Anna Lippel --
2015 May 04
2
Define replacement functions
Hello I tried to define replacement functions for the class "mylist". When I test them in an active R session, they work -- however, when I put them into a package, they don't. Why and how to fix? make_my_list <- function( x, y ) { return(structure(list(x, y, class="mylist"))) } mylist <- make_my_list(1:4, letters[3:7]) mylist mylist[['x']] <- 4:6
2011 Sep 09
1
Adding groups to regression line panel function in Lattice
I wish to display a single-panel Lattice figure with grouped data and fitted regression lines. I don't seem to be able to get the individual regression lines to display, e.g.; d <- data.frame(q = rep(1:6, each=10), cc = rep(seq(10,100, 10),6)) # create data frame with group identifier 'q', independent variable cc d$ba = d$q*0.1*d$cc + 5*rnorm(nrow(d))