similar to: Compare each element of a list to a vector

Displaying 20 results from an estimated 10000 matches similar to: "Compare each element of a list to a vector"

2004 Sep 16
1
barplot with vcd library
'barplot' doesn't seem to work with vcd library. Am I supposed to detach vcd when I want to use barplot? Here's an example. Say I have the following matrix, > m <- matrix(c(1,2,3, 4,5,6, 3,4,5, 2,3,4), ncol=4) > m [,1] [,2] [,3] [,4] [1,] 1 4 3 2 [2,] 2 5 4 3 [3,] 3 6 5 4 Then > barplot(m) gives a barplot of the data. However,
2011 Aug 31
1
Convert List of Data.Frames to Data.Frame when List has NULL
Dear R gurus, I trying to convert a list of data frames to one data frame, but one of the values within the list is NULL, so I get the error "arguments imply differing number of rows." Do you know of a quick way to tell R to combine all that are not null? Here is a simple example: >
2003 Jun 10
1
c(...) and methods
I have been writing some S4 classes and have a problem about how I might pass a signature to "c()". Take the following example: setClass("collection", representation("list", date="POSIXt")) x <- new("collection", list(1,2,3), date=Sys.time()) y <- new("collection", list(4,5,6), date=Sys.time()) obviously, I can do c(x,y), but
2009 Jun 30
1
How to wrap my (working) code in a loop or function? (loop/function newbie alert)
Dear R-helpers, I have split a dataframe into a list with five elements, with the following code: > datalist<-split(data,data$UNIT) I would now like to run some code (below) on each element of the list to extract rows from the list elements; then I would like to rbind the extracted rows into a new dataframe containing all of the extracted rows from all of the list elements. I don't
2005 Mar 28
2
Generating list of vector coordinates
Hi. Can anyone suggest a simple way to obtain in R a list of vector coordinates of the following form? The code below is Mathematica. In[5]:= Flatten[Table[{i,j,k},{i,3},{j,4},{k,5}], 2] Out[5]= {{1,1,1},{1,1,2},{1,1,3},{1,1,4},{1,1,5},{1,2,1},{1,2,2},{1,2,3},{1 ,2,4},{1,2, 5},{1,3,1},{1,3,2},{1,3,3},{1,3,4},{1,3,5},{1,4,1},{1,4,2},{1,4,3}, {1,4,
2008 Dec 16
2
Problem assigning "NA" as a level name in a list
I want to generate a list (called "dataList" below) where each of its levels is named. These names are assigned to nameList, which contains all possible permutations of size two taking letters from a larger alphabet, e.g., "aa",...,"Fd",..,"Z1",... One of these permutations is the character string "NA". It seems that when I try to name one
2012 Feb 21
3
Plot Many Data to same plot
Dear all, I have a function that for a variable number of inputs plots them to the same plot I am doing this quite simply by plot(seq(from=start, to=stop, length.out=np), datalist[[1]]$dataset                                                                  xlim=c(start, stop), ylim=c(0, 1), type="l")                                                                                      
2007 Dec 20
1
auto named savings (pngs & data-frames)
Hello, i only got a small problem. i try to create automatic new dataframes, or png?s. the main problem i got is: how can i create automatic a new name for a file (read out by simply "for") - i tried to use "(paste...) but theres an errormessage, about a wrong declination. R told it is as.character, but need as.Real. Should i use another method than "paste"? i tried as
2012 May 22
1
confused with indexing
Dear all, I have a code that looks like the following (I am sorry that this is not a reproducible example)     indexSkipped<-NULL  ....code Skipped that might alter indexSkipped     if (length(indexSkipped)==0)         spatial_structure<-spatial_structures_from_measurements(DataList[[i]]$Lon,DataList[[i]]$Lat,meanVector)     else        
2004 Apr 08
1
Why are Split and Tapply so slow with named vectors, why is a for loop faster than mapply
First, here's the problem I'm working on so you understand the context. I have a data frame of travel activity characteristics with 70,000+ records. These activities are identified by unique chain numbers. (Activities are part of trip chains.) There are 17,500 chains. I use the chain numbers as factors to split various data fields into lists of chain characteristics with each element of
2008 Feb 21
3
applying a function to data frame columns
useR's, I want to apply this function to the columns of a data frame: u[u >= range(v)[1] & u <= range(v)[2]] where u is the n column data frame under consideration and v is a data frame of values with the same number of columns as u. For example, v1 <- c(1,2,3) v2 <- c(3,4,5) v3 <- c(2,3,4) v <- as.data.frame(cbind(v1,v2,v3)) uk1 <- seq(min(v1) - .5, max(v1) + .5,
2004 Sep 14
1
Re: datalist
Hi, The following is a cut/paste from http://developer.r-project.org/200update.txt: ... 3) When a package is installed, all the data sets are loaded to see what they produce. If this is undesirable (because they are enormous, or depend on other packages that need to be installed later, ...), add a `datalist' file to the data subdirectory as described in `Writing R
2012 Jun 20
2
passing function parameters into a 'with' statement to dynamically pick out columns
Hi, I've built a function to generate plots and would like to be able pass in column names as a parameter. Here's a boiled down version of what I have right now: pmts <- data.frame(date=c(1,2,3), all=c(5,6,7),maj=c(4,5,6),ind=c(3,4,5)) perc.mktshare <- function(df){ range1 <- floor(min(with(df, 100*ind/all))) range2 <- ceiling(max(with(df, 100*ind/all)))
2013 Mar 23
1
sysdata.rda vs. rda files in data directory
Dear developeRs, my package FrF2.catlg128 holds large catalogues and is supposed to gain additional ones. All the catalogues are intended for the user. So far, the catalogues were stored in the data directory, and LazyData was "no". I understand that this is not considered wise any more (if it ever was), so that I want to change to LazyData "yes" with the next release
2006 Feb 21
6
How to sum values across multiple variables using a wildcard?
I have a dataframe called "data" with 5 records (in rows) each of which has been scored on each of many variables (in columns). Five of the variables are named var1, var2, var3, var4, var5 using headers. The other variables are named using other conventions. I can create a new variable called var6 with the value 15 for each record with this code: > var6=var1+var2+var3+var4+var5
2009 May 22
1
regrouping factor levels
Hi all, I had some trouble in?regrouping factor levels for a variable. After some experiments, I have figured out how I can recode to modify the factor levels. I would now like some help to understand why some methods work and others don't. Here's my code : rm(list=ls()) ###some trials in recoding factor levels char<-letters[1:10] fac<-factor(char) levels(fac) print(fac) ##first
2006 Feb 12
1
mean from list
hi all, I have a simple problem that i am not able to solve. I've a list called datalist with the following structure: [...] [[10]] [[10]]$a -1 0 1 -1 31 5 2 0 6 7 5 1 1 7 36 [[10]]$b -1 0 1 -1 31 5 2 0 6 7 5 1 1 7 36 [[10]]$c [1] 0.855 [[10]]$d [1] 0.855 [...] with [[1]] ... [[100]]. How can i get the mean value of datalist[[x]]$d, where x
2010 Apr 22
2
Compare two data frames
I wonder if there is a more efficient way to do this task. Suppose I have two data frames, such as d1 <- data.frame(x = c(1,2,3), y = c(4,5,6), z = c(7,8,9)) d2 <- d1[, c('y', 'x')] The first dataframe d1 has more variables than d2 and the variable columns are in a different order. So, what I want to do is compare the two frames on the variables that are common between
2017 Dec 04
0
Dynamic reference, right-hand side of function
The generic rule is that R is not a macro language, so looping of names of things gets awkward. It is usually easier to use compound objects like lists and iterate over them. E.g. datanames <- paste0("aa_", 2000:2007) datalist <- lapply(datanames, get) names(datalist) <- datanames col1 <- lapply(datalist, "[[", 1) colnum <- lapply(col1, as.numeric) (The 2nd
2010 Apr 05
3
Matrix elements are vectors
Dear all, My question how is it possible to define a matrix A with 10 rows 1 column, so that its elements are vectors of undefined length. I need to have a possibility later to add elements like A[1,1] <- c(A[1,1],3,4,5) Thanks a lot for the help! [[alternative HTML version deleted]]