similar to: grabbing from elements of a list without a loop

Displaying 20 results from an estimated 3000 matches similar to: "grabbing from elements of a list without a loop"

2013 Feb 01
2
expand.grid on contents of a list
Hello! I have a list of variable length. One example is: X=vector("list",3) X[[1]]=1:2 X[[2]]=1:2 X[[3]]=1:2 How could I run expand.grid on the elements of X so that the results would be the same as expand.grid(1:2,1:2,1:2)? Thank you! Dimitri -- Dimitri Liakhovitski gfk.com <http://marketfusionanalytics.com/> [[alternative HTML version deleted]]
2013 Jan 29
4
Fastest way to compare a single value with all values in one column of a data frame
Hello! I have a large data frame x: x<-data.frame(item=letters[1:5],a=1:5,b=11:15) # in actuality, x has 1000 rows x$item<-as.character(x$item) I also have a small data frame y with just 1 row: y<-data.frame(item="f",a=3,b=10) y$item<-as.character(y$item) I have to decide if y$a is larger than the smallest of all the values in x$a. If it is, I want y to replace the whole
2013 Feb 07
1
Select only unique rows from a data frame
Hello! I have a data frame with several rows, for example: x=as.data.frame(matrix(c(1,2,3, 1,2,3, 1,2,2, 1,2,2, 1,1,1),ncol=3,byrow=T)) I would like to find y - a data frame that only has the unique rows from x, i.e.: 1,2,3 1,2,2 1,1,1 Thanks a lot for your hints! Dimitri -- Dimitri Liakhovitski gfk.com <http://marketfusionanalytics.com/> [[alternative HTML
2013 Feb 03
1
Looping through rows of all elements of a list that has variable length
Dear R-ers, I have a list of data frames such that the length of the list is unknown in advance (it could be 1 or 2 or more). Each element of the list contains a data frame. I need to loop through all rows of the list element 1 AND (if applicable) of the list element 2 etc. and do something at each iteration. I am trying to figure out how to write a code that is generic, i.e., loops through the
2004 Sep 12
2
boxplot() from list
I have a list containing 48 objects (each with 30 rows and 4 columns, all numeric), and wish to produce 4 boxplot series (with 48 plots in each) , one for each column of each object. Basically I want a boxplot from boxplot(mylist[[]][,i]) for i in 1:4. It seems that I can create a boxplot of length 48 from the entire list, but I don't seem able to subscript to return 4 boxplots from the list
2012 Dec 07
2
Assigning cases to groupings based on the values of several variables
Dear R-ers, my task is to simple: to assign cases to desired groupings based on the combined values on 2 variables. I can think of 3 methods of doing it. Method 1 seems to me pretty r-like, but it requires a lot of lines of code - onerous. Method 2 is a loop, so not very good - as it loops through all rows of mydata. Method 3 is a loop but loops through fewer lines, so it seems to me more
2018 Apr 15
4
Adding a new conditional column to a list of dataframes
Hi all .., I have a list of 7000 dataframes with similar column headers and I wanted to add a new column to each dataframe based on a certain condition which is the same for all dataframes. When I extract one dataframe and apply my code it works very well as follows :- First suppose this is my first dataframe in the list > OneDF <- Mylist[[1]] > OneDF ID Pdate
2010 Jun 28
2
ask a question about list in R project
my list al is as below: mylist=list(c(2,3),5,7) > mylist [[1]] [1] 2 3 [[2]] [1] 5 [[3]] [1] 7 How could I get the following FOUR lists: First one [[1]] [1] 3 [[2]] [1] 5 [[3]] [1] 7 Second one [[1]] [1] 2 [[2]] [1] 5 [[3]] [1] 7 Third One [[1]] [1] 2 3 [[2]] [1] 7 Last one [[1]] [1] 2 3 [[2]] [1] 5 Do I have to use 'for' loops? Please give me sone suggestions! Thank you
2011 Sep 16
2
"rounding" to a number that is LOWER than my number
Hello! What function would allow me to "round" down, rather than up? For example, x<-1.98 I'd like to get 1.9 - rather than 2.0. Reason - I am creating a minimum for an axis for a plot, and I need it to be lower than x (which, in turn, is the lowest number already). Thank you! -- Dimitri Liakhovitski marketfusionanalytics.com
2011 Aug 05
2
summing columns with NAs present
Hello! I have a data frame with some NAs. test<-data.frame(a=c(1,2,NA),b=c(10,NA,20)) I need to sum up values in 2 variables. However: test$a+test$b procudes NAs in rows that have NAs. How could I sum up columns while ignoring NAs (the way the function sum(..., na.rm=T) works? Thank you! -- Dimitri Liakhovitski marketfusionanalytics.com
2018 Apr 15
0
Adding a new conditional column to a list of dataframes
> On Apr 15, 2018, at 4:08 AM, Allaisone 1 <Allaisone1 at hotmail.com> wrote: > > > Hi all .., > > > I have a list of 7000 dataframes with similar column headers and I wanted to add a new column to each dataframe based on a certain condition which is the same for all dataframes. > > > When I extract one dataframe and apply my code it works very well as
2011 Aug 04
2
Efficient way of creating a shifted (lagged) variable?
Hello! I have a data set: set.seed(123) y<-data.frame(week=seq(as.Date("2010-01-03"), as.Date("2011-01-31"),by="week")) y$var1<-c(1,2,3,round(rnorm(54),1)) y$var2<-c(10,20,30,round(rnorm(54),1)) # All I need is to create lagged variables for var1 and var2. I looked around a bit and found several ways of doing it. They all seem quite complicated - while in
2011 Aug 01
1
Identifying US holidays
Hello! I am trying to identify which ones of a vector of dates are US holidays. And, ideally, which is which. And I do not know (a-priori) which dates those should be. I have, for example: x<-seq(as.Date("2011-01-01"),as.Date("2011-12-31"),by="day") (x) I think chron should help me here - but maybe I am not using it properly: library(chron) is.holiday(chron) #
2011 Nov 10
3
optim seems to be finding a local minimum
Hello! I am trying to create an R optimization routine for a task that's currently being done using Excel (lots of tables, formulas, and Solver). However, otpim seems to be finding a local minimum. Example data, functions, and comparison with the solution found in Excel are below. I am not experienced in optimizations so thanks a lot for your advice! Dimitri ### 2 Inputs:
2012 Jan 27
1
Overimposing one map in ssplot onto another
Hello! I have 2 maps - both created in ssplot and both identical in terms of outline. Is there any way to superimpose Map1 (which has black borders between Canadian provinces) onto Map2 (which is also a map of Canada)? Thanks a lot for your hints! Dimitri ### A. Reading in Canada data at the province and then at the county level: library(raster) getData('ISO3') # Canada's code is
2011 Jul 21
4
squared "pie chart" - is there such a thing?
Hello! It's a shoot in the dark, but I'll try. If one has a total of 100 (e.g., %), and three components of the total, e.g., mytotal=data.frame(x=50,y=30,z=20), - one could build a pie chart with 3 sectors representing x, y, and z according to their proportions in the total. I am wondering if it's possible to build something very similar, but not on a circle but in a square - such that
2011 Aug 02
3
identifying weeks (dates) that certain days (dates) fall into
Hello! I have dates for the beginning of each week, e.g.: weekly<-data.frame(week=seq(as.Date("2010-04-01"), as.Date("2011-12-26"),by="week")) week # each week starts on a Monday I also have a vector of dates I am interested in, e.g.: july4<-as.Date(c("2010-07-04","2011-07-04")) I would like to flag the weeks in my weekly$week that
2011 Jul 19
1
calculating mean excluding zeros
Sorry if it's been discussed before - don't seem to find it. I'd like to calculate a mean while ignoring zeros. "mean" doesn't seem to have an option for that. Any other function/package that could do it? Thanks for a pointer! -- Dimitri Liakhovitski marketfusionanalytics.com
2011 Jul 29
1
splitting a string based on the last underscore
Hello! Hope you could help me split the strings. I have a set of strings: x<-c("name_a1_2.5.o","name_a2_2.53.o","name_a3_bla_1.o") I need to extract from each string: 1. Its unique part that comes before the last "_", i.e.: "a1","a2","a3_bla". 2. The part that comes after the last "_" and before ".o"
2012 Nov 19
1
(no subject)
Dear R-ers, I have 3 vectors - x, y, and z and want to plot a surface (z as the 3rd dimension): x<- c(-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1) y<- c(-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1) z<- c(0.226598762, 0.132395904, 0.14051906, 0.208607098, 0.320840304, 0.429423216, 0.54086732, 0.647792527, 0.256692375, 0.256403273, 0.172881269, 0.121978079,