similar to: Extending each element in a list, or rbind()-ing arrays of different length without recycling

Displaying 20 results from an estimated 30000 matches similar to: "Extending each element in a list, or rbind()-ing arrays of different length without recycling"

2017 Dec 13
0
Add vectors of unequal length without recycling?
Without recycling you would get: u <- c(10, 20, 30) u + 1 #[1] 11 20 30 which would be pretty inconvenient. (Note that the recycling rule has to make a special case for when one argument has length zero - the output then has length zero as well.) Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Dec 12, 2017 at 9:41 PM, Maingo via R-help <r-help at r-project.org> wrote:
2017 Dec 13
4
Add vectors of unequal length without recycling?
I'm a newbie for R lang. And I recently came across the "Recycling Rule" when adding two vectors of unequal length. I learned from this tutor [ http://www.r-tutor.com/r-introduction/vector/vector-arithmetics ] that: """""" If two vectors are of unequal length, the shorter one will be recycled in order to match the longer vector. For example, the
2011 Dec 01
1
strange row numbering after rbind-ing a list
"Not that it really matters, but" Can someone explain how the row numbers get assigned in the following sequence? It looks like something funky happens when rbind() coerces 'bar' into a dataframe. In either sequence of rbind below, once you get past the first two rows, the row numbers count normally. Rgames> (foo<-data.frame(x=5,y=4,r=3)) x y r 1 5 4 3 Rgames>
2007 Jan 30
2
rbind-ing list
hi, i have a list of data.frame that has same structure. i would like to know a efficient way of rbind-ing it. right now, i write: n = length(temp) # 'temp' is a list of data.frames temp2 = data.frame() for (i in 1:n) temp2 = rbind( temp2, temp[[i]]) return(temp2) but this is not an efficient way since we keeping overwriting temp2. i wonder if there's faster way. thanks --
2012 May 01
2
rbind-ing numeric matrices
Good morning, I'm running into trouble rbind-ing numeric matrices with differing numbers of rows. In particular, there seem to be issues whenever a one-row numeric matrix is involved. Assume A is a numeric matrix with 1 row and Y columns and B is a numeric matrix with X rows and Y columns. Let C be the result of rbinding A and B. Then C is a numeric matrix with X + 1 rows and Y columns, only
2007 Apr 03
5
converting a list to a data.frame
Hello, I have a list with n numerical components of different length (3, 4 or 5 values in each component of the list); I need to export this as a text file where each component of the list will be a row and where missing values should fill in the blanks due to the different lengths of the components of the list. I think that as a first step I should convert my list to a data frame, but this is
2010 Oct 14
1
rbind ing matrices and resetting column numbers
Sorry for the verbose example. I want to row bind two matrices, and all works except I want the column labelled "row" to be sequential in the new matrix, shown as "mat3" here, i.e. needs to be 1:6 and not 1:3 repeated twice. Any suggestions? Thanks J > colnm1 <- c("row","ti","counti") > colnm2 <-
2007 Jan 25
4
rbind-ing with empty data frame produces error
Hi all, I'm having some trouble with rbind - this may be a bug or it may be my misunderstanding. If I do fileName <- paste(tempdir(),"test.txt",sep="/") file.create(fileName) x <- read.table(fileName, col.names=c("one","two","three")) I get a data frame with no rows, as documented. If I then try to rbind this with another data frame
2007 Dec 26
2
Rbind-ing a list into one item
Hi, I am doing the following: 1. I have a list of files.. Files1=list.files("some directory",pattern="some pattern") 2. I define a list as res=vector("list", length(files1)) 3. I read all the files into this list: res=lapply(files1, read.csv) I now want to rowbind all the items in the list into one big mass (all files have same number of columns). I tried
2008 Mar 13
2
How to cbind or rbind different lengths vectors/arrays without repeating the elements of the shorter vectors/arrays ?
Hi, How to cbind or rbind different lengths vectors/arrays without repeating the elements of the shorter vectors/arrays ? > cbind(1:2, 1:10) [,1] [,2] [1,] 1 1 [2,] 2 2 [3,] 1 3 [4,] 2 4 [5,] 1 5 [6,] 2 6 [7,] 1 7 [8,] 2 8 [9,] 1 9 [10,] 2 10 [[alternative HTML version deleted]]
2012 Mar 15
2
how to bind uneven column (not equal length) into matrix without recycling values
i have > x [1] 1 2 3 4 5 6 > y [1] 34 5 6 > z<-cbind(x,y) > z x y [1,] 1 34 [2,] 2 5 [3,] 3 6 [4,] 4 34 [5,] 5 5 [6,] 6 6 i don't want recycling, instead can we put NA /0 like below> z x y [1,] 1 34 [2,] 2 5 [3,] 3 6 [4,] 4 NA [5,] 5 NA [6,] 6 NA & want distance matrix -- View this message in context:
2009 Feb 18
1
rbind: number of columns of result is not a multiple of vector length (arg 1)
i have the following constructed and running very well,, thanks to Gabor Grothendieck for his help. >data.info <- c("station.id", "year", "date", "max.discharge") > > for(i in 1:num.files) { + station.id <- substring(data[i], 1,8) + DF <- read.table(data[i], sep=",", blank.lines.skip = TRUE) + z <- zoo(DF[,4],
2010 Jun 04
2
Argument recycling in substring()
Hi, According to its man page substring() "expands (its) arguments cyclically to the length of the longest _provided_ none are of zero length". So, as expected, I get an error here: > substring("abcd", first=2L, last=integer(0)) Error in substring("abcd", first = 2L, last = integer(0)) : invalid substring argument(s) But I don't get one here:
2010 Nov 08
7
How to rbind list of vectors with unequal vector lengths?
Hi, How to rbind these vectors from a list?: > l <- list(a = c(1, 2), b = c(1, 2, 3)) > l $a [1] 1 2 $b [1] 1 2 3 > do.call(rbind, l) [,1] [,2] [,3] a 1 2 1 b 1 2 3 Warning message: In function (..., deparse.level = 1) : number of columns of result is not a multiple of vector length (arg 1) > -J
2011 Jan 06
5
How to join matrices of different row length from a list
Hi, I have several matrix in a list, for example: e [[1]] [,1] [,2] [1,] 1 3 [2,] 2 4 [[2]] [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 [[3]] [,1] [,2] [1,] 2 1 I would like to join them by column i.e. [,1] [,2] [,3] [,4][,5] [,6] [1,] 1 3 1 4 2 1 [2,] 2 4 2 5 NA NA [3,] NA NA 3 6 NA NA I have tried
2009 Apr 10
3
Determine the Length of the Longest Word in a String
Hi Everyone, I'm new to programming R and have accomplished my goal, but feel that there is probably a more efficient way of coding this. I'd appreciate any guidance that a more advanced programmer can provide. My goal -- I would like to find the length of the longest word in a string containing many words separated by spaces. How I did it -- I was able to find the length of the
2009 Jan 07
5
rbind for matrices - rep argument
Dear R users,I'm facing a trivial problem, but I really can't solve it. I've tried a dozen of codes, but I can't get the result I want. The question is: I have a dataframe like this one [,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5 [2,] 2 5 5 4 9 [3,] 1 6 8 1 2 [4,] 8 6 4 1 5 made up of decimal numbers, of course. I want to
2018 Jan 04
3
silent recycling in logical indexing
Sorry if this has been covered here somewhere in the past, but ... Does anyone know why logical vectors are *silently* recycled, even when they are incommensurate lengths, when doing logical indexing? This is as documented: For ?[?-indexing only: ?i?, ?j?, ?...? can be logical vectors, indicating elements/slices to select. Such vectors are recycled if necessary to match
2019 May 16
5
nrow(rbind(character(), character())) returns 2 (as documented but very unintuitive, IMHO)
Hi all, Apologies if this has been asked before (a quick google didn't find it for me),and I know this is a case of behaving as documented but its so unintuitive (to me at least) that I figured I'd bring it up here anyway. I figure its probably going to not be changed, but I'm happy to submit a patch if this is something R-core feels can/should change. So I recently got bitten by
1999 Nov 23
2
rbind problem (PR#338)
In the new version 0.90.0, rbind won't take a vector and a matrix from me, but works OK if I coerce the vector to a matrix. The following was run on a new session (i.e., no prior work), and has been duplicated on 2 machines: an SGI running Irix 6.5, and an Intel box running Red Hat Linux 6.0. Either case works fine in version 0.65.1. > t3 <- c(.5, .5) > t4 <-