Re: [R] rbind of multiple data frames by column name, when each data frames can contain different columns

2022-06-03 Thread Avi Gross via R-help
Message- From: CALUM POLWART To: Bert Gunter Cc: r-help@R-project.org ; Stefano Sofia Sent: Fri, Jun 3, 2022 3:48 am Subject: Re: [R] rbind of multiple data frames by column name, when each data frames can contain different columns Bert! It sounds like you are warming to the the tidyverse

Re: [R] rbind of multiple data frames by column name, when each data frames can contain different columns

2022-06-03 Thread John Fox
arche Region - Italy Meteo Section Snow Section Via del Colle Ameno 5 60126 Torrette di Ancona, Ancona (AN) Uff: +39 071 806 7743 E-mail: stefano.so...@regione.marche.it ---Oo-oO ____________ Da: Andrew Simmons Inviato: venerd� 3

Re: [R] rbind common header to file list

2021-01-21 Thread Miluji Sb
Thank you, that was it. Best, Milu On Wed, Jan 20, 2021 at 1:33 PM Eric Berger wrote: > for ( file in filelist ) > > > > On Wed, Jan 20, 2021 at 2:21 PM Miluji Sb wrote: > >> Thank you for your reply and the solution. Yes, I would like the date to >> be >> the column header for all the files

Re: [R] rbind common header to file list

2021-01-20 Thread Eric Berger
for ( file in filelist ) On Wed, Jan 20, 2021 at 2:21 PM Miluji Sb wrote: > Thank you for your reply and the solution. Yes, I would like the date to be > the column header for all the files in the list. > > This is what tried following your suggestion; > > filelist = list.files(pattern = ".*.t

Re: [R] rbind common header to file list

2021-01-20 Thread Miluji Sb
Thank you for your reply and the solution. Yes, I would like the date to be the column header for all the files in the list. This is what tried following your suggestion; filelist = list.files(pattern = ".*.txt") date <- 2101 for (file %in% filelist){ datalist <- read.table(file) write.t

Re: [R] rbind common header to file list

2021-01-19 Thread Jeff Newmiller
a) I recommend _not_ overwriting the input files. Very difficult to debug/recover if anything goes wrong. b) I recommend making a function that takes the file name, source directory, and destination directory, and reads the file, makes the change, and writes it to the output directory. c) Your

Re: [R] rbind - names in dataframe. Beginner Question

2015-10-29 Thread Dagmar
Hello Rui and Gerrit and Sarah, Thank you very much for your help. I finally got it to work! Have a great day! Dagmar Am 29.10.2015 um 08:38 schrieb ruipbarra...@sapo.pt: > > Hello, > > Try the following. > > > newframe <- myframe > newframe$Hungertype <- with(myframe, ifelse(Hunger <= 1, NA, >

Re: [R] rbind - names in dataframe. Beginner Question

2015-10-29 Thread Gerrit Eichner
Hello, Sarah, take a look at the online help page of the function cut() (and apply the function to the Hunger-column). Hth -- Gerrit On Thu, 29 Oct 2015, Dagmar wrote: Dear Sarah, (dear All), Thank you for trying to help! You are right, that I want to add a column to my dataframe with a

Re: [R] rbind - names in dataframe. Beginner Question

2015-10-29 Thread ruipbarradas
Hello, Try the following. newframe <- myframe newframe$Hungertype <- with(myframe, ifelse(Hunger <= 1, NA,                             ifelse(1 < Hunger & Hunger <= 2, "Hunger",                             ifelse(Hunger < 3, "bigHUnger", "verybigHunger") ))) Note that the new column is of type c

Re: [R] rbind - names in dataframe. Beginner Question

2015-10-29 Thread Dagmar
Dear Sarah, (dear All), Thank you for trying to help! You are right, that I want to add a column to my dataframe with a corresponding value to the Hunger column. Your solution is basically correct in the result but my data are a little more complicated. Maybe that example describes it better:

Re: [R] rbind - names in dataframe. Beginner Question

2015-10-28 Thread Sarah Goslee
If I'm reading this correctly, you want to add a column to your dataframe with a name corresponding to the value in the Hunger column. myframe <- data.frame (ID=c("Ernie", "Ernie", "Ernie", "Bert", "Bert","Bert", "Duck"), Hunger=c(1,1,1,2,2,1,3) ) myframe$Hungertype <- c("none", "bighunger", "ver

Re: [R] rbind in array of lists

2014-10-12 Thread Rui Barradas
Hello, Em 12-10-2014 18:26, David Winsemius escreveu: On Oct 12, 2014, at 8:45 AM, Rui Barradas wrote: Hello, Try the following. do.call(rbind, lapply(a, '[[', "var1")) do.call(rbind, lapply(a, '[[', "var2")) Could perhaps (untested) make it more general with: do.call(rbind, lapply(a, '[

Re: [R] rbind in array of lists

2014-10-12 Thread David Winsemius
On Oct 12, 2014, at 8:45 AM, Rui Barradas wrote: > Hello, > > Try the following. > > do.call(rbind, lapply(a, '[[', "var1")) > do.call(rbind, lapply(a, '[[', "var2")) Could perhaps (untested) make it more general with: do.call(rbind, lapply(a, '[[', names(a[[1]])[1])) do.call(rbind, lapply(a,

Re: [R] rbind in array of lists

2014-10-12 Thread Rui Barradas
Hello, Try the following. do.call(rbind, lapply(a, '[[', "var1")) do.call(rbind, lapply(a, '[[', "var2")) Hope this helps, Rui Barradas Em 12-10-2014 07:14, Cesar Caballero escreveu: Hi all, I have an array of lists. All lists have the same names and the vectors inside each name have the

Re: [R] rbind multiple data sets (.csv)

2014-06-11 Thread arun
Hi, If your working directory is "data 3" which has only two folders C1 and C2. May be this helps: lsF1 <- list.files(recursive=TRUE) lst1 <- lapply(split(lsF1,gsub(".*\\_(\\d+)\\..*","\\1",lsF1)),function(x) do.call(rbind,lapply(x,function(y) read.csv(y, header=TRUE A.K. Hello, I am tryi

Re: [R] rbind/timestamp problem

2013-12-10 Thread Georg Hörmann
Thank you, now it works. I would never have never found the source of the problem. I am trying to build a data frame with results from a sensitivity analysis for a model. I use rbind because the number of rows is unkown and i use the timestamp as a hint for the students that they do not analyse

Re: [R] rbind/timestamp problem

2013-12-10 Thread jim holtman
try this: > sensitivity=rbind(sensitivity,data.frame(mtype=2,cdate=as.POSIXct(Sys.time(), > origin="1970-01-01"))) > sensitivity mtype cdate 1 1 2013-12-10 09:35:53 2 2 2013-12-10 09:37:02 The 'c' function is coercing to numeric. If you want to 'rbind' rows to a datafram

Re: [R] rbind a list of matrices

2013-03-07 Thread Berend Hasselman
On 07-03-2013, at 17:52, Heath Blackmon wrote: > I have a large list of matrices and a vector that identifies the desired > matrices that I would like to rbind. However, I am stuck on how to get > this to work. I have written some code below to illustrate my problem: > > # 3 simple matrices >

Re: [R] rbind a list of matrices

2013-03-07 Thread Bert Gunter
?do.call ## as in do.call(rbind, list_of_matrices) ## Note that list_of_matrices must be a **list**. -- Bert On Thu, Mar 7, 2013 at 8:52 AM, Heath Blackmon wrote: > I have a large list of matrices and a vector that identifies the desired > matrices that I would like to rbind. However, I am

Re: [R] rbind a list of matrices

2013-03-07 Thread arun
Not sure if this what you wanted.  do.call(rbind,(matrix.list[desired.matrices])) # [,1] [,2] [,3] #[1,]    1    4    7 #[2,]    2    5    8 #[3,]    3    6    9 #[4,]   19   22   25 #[5,]   20   23   26 #[6,]   21   24   27 A.K. From: Heath Blackmon To: r-

Re: [R] rbind Missing Something: Need New Eyes

2013-01-31 Thread Peter Langfelder
On Thu, Jan 31, 2013 at 3:55 PM, Rich Shepard wrote: > I don't see what's missing in my statements to add rows to a data frame > and someone else will probably see what needs to be added to the statements. > > The data frame has this structure (without any data): > > $ PHYLUM : chr > $

Re: [R] rbind Missing Something: Need New Eyes [RESOLVED]

2013-01-31 Thread Rich Shepard
On Thu, 31 Jan 2013, Rich Shepard wrote: I don't see what's missing in my statements to add rows to a data frame and someone else will probably see what needs to be added to the statements. Found the problem: a FUBAR'd R session. Rich __ R-hel

Re: [R] rbind: inconsistent behaviour with empty data frames?

2013-01-03 Thread Dmitrii Izgurskii
What version of R are you using? I am using version 2.15.1. Suddenly everything works correctly too. I guess a restarting R did the trick. On 01/02/2013 10:25 PM, David L Carlson wrote: What version of R are you using? I cannot replicate your results with R 2.15.2: df1 <- data.frame() df2

Re: [R] rbind: inconsistent behaviour with empty data frames?

2013-01-02 Thread David L Carlson
What version of R are you using? I cannot replicate your results with R 2.15.2: > df1 <- data.frame() > df2 <- data.frame(foo=c(1, 2), bar=c("a", "b")) > rbind(df1, df2) foo bar 1 1 a 2 2 b > df1 <- data.frame(matrix(0, 0, 2)) > names(df1) <- names(df2) > rbind(df1, df2) foo bar 1 1

Re: [R] rbind in a loop with " : " elements

2012-08-22 Thread bilelsan
You are a GENIUS !! I don't know how to thank you !! Thank you so much ! I really need to improve my R language (I take any advice) If i can do something for you about MGARCH models, let me know Thx again Bilel Le Aug 22, 2012 à 8:55 PM, Rui Barradas [via R] a écrit : > Hello, > > I'm being

Re: [R] rbind in a loop with " : " elements

2012-08-22 Thread Rui Barradas
Hello, I'm being lazy, but the following works. r = 3 ; set.seed(1) v <- matrix(c(rnorm(40)),10,4) result <- vector("list", r*ncol(v)) ires <- 0 for (j in 1:4){ for (i in 1:r){ x <- t(v[,j]^(i)*v[,1:4]^((r-(4-1)):r)) #print(x) ires <- ires + 1 result[[ ires

Re: [R] rbind-ing numeric matrices

2012-05-01 Thread Sarah Goslee
On Tue, May 1, 2012 at 2:12 PM, Nick Switanek wrote: > Thank you, Sarah! > > Yes, unlist() looks like it will do just what I need. Thank you. > > I took a different tack. I'd changed the function returning A to coerce the > row from the data.frame using as.numeric(). Any reason to prefer your way

Re: [R] rbind-ing numeric matrices

2012-05-01 Thread Nick Switanek
Thank you, Sarah! Yes, unlist() looks like it will do just what I need. Thank you. I took a different tack. I'd changed the function returning A to coerce the row from the data.frame using as.numeric(). Any reason to prefer your way or mine? thanks again, Nick On Tue, May 1, 2012 at 2:08 PM, S

Re: [R] rbind-ing numeric matrices

2012-05-01 Thread Sarah Goslee
Hi Nick, On Tue, May 1, 2012 at 1:56 PM, Nick Switanek wrote: > Thank you, Steve and Sarah, for your swift replies. > > I didn't know about dput(). class() returns "matrix" for A, B, and C, but > here: > >> class(A) > [1] "matrix" >> class(B) > [1] "matrix" >> dput(A) > structure(list(1239814462,

Re: [R] rbind-ing numeric matrices

2012-05-01 Thread Nick Switanek
Thank you, Steve and Sarah, for your swift replies. I didn't know about dput(). class() returns "matrix" for A, B, and C, but here: > class(A) [1] "matrix" > class(B) [1] "matrix" > dput(A) structure(list(1239814462, 1239814601, 14349, 3, 4, 0, 12, 46601, 17801, 12401, 106001), .Dim = c(1L, 1

Re: [R] rbind-ing numeric matrices

2012-05-01 Thread Steve Lianoglou
Hi, On Tue, May 1, 2012 at 11:52 AM, Nick Switanek wrote: > 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 a

Re: [R] rbind-ing numeric matrices

2012-05-01 Thread Sarah Goslee
Hi Nick, We absolutely need a reproducible example, with code and data, to be able to help you. Because otherwise I can't replicate your problem: > A <- matrix(1:5, nrow=1, ncol=5) > B <- matrix(6:20, nrow=3, ncol=5) > C <- rbind(A, B) > A [,1] [,2] [,3] [,4] [,5] [1,]1234

Re: [R] rbind()

2012-01-20 Thread MacQueen, Don
As Sarah said, you have a path problem. Are you saying that RawData is a sub-folder (sub-directory) of SampleProject? And you are running the script with the working directory set to SampleProject? [check using getwd() as Sarah suggested] If so, it looks like it would work if you use './RawData/F

Re: [R] rbind()

2012-01-20 Thread Sarah Goslee
Hi Fred, It seems you don't have an rbind() problem, but a path problem. The error you're getting means R can't find your file. When specifying a relative path, as you do with "../RawData/File1.csv" it's relative to your current working directory, not necessarily the directory where your script i

Re: [R] rbind/cbind

2011-08-10 Thread ONKELINX, Thierry
50 > Aan: Anthony Ching Ho Ng > CC: r-help@r-project.org > Onderwerp: Re: [R] rbind/cbind > > > On Aug 10, 2011, at 9:08 AM, Anthony Ching Ho Ng wrote: > > > Dear list, > > > > I wonder if there a better way to have rbind/cbind/append to create > > the firs

Re: [R] rbind/cbind

2011-08-10 Thread David Winsemius
On Aug 10, 2011, at 9:08 AM, Anthony Ching Ho Ng wrote: Dear list, I wonder if there a better way to have rbind/cbind/append to create the first element (if it is empty) instead of doing the following in a loop? for (i in 1:10) { if (i == 1) { aRow = SomeExpression(i) } else { aRow =

Re: [R] rbind with partially overlapping column names

2011-05-16 Thread Jonathan Flowers
Hi all, Thanks for your responses. The merge output works for the test case as Bill pointed out, but is contingent on non-overlapping values. Thanks for pointing this out Ian. My actual dataset needs to allow for overlapping values (sorry for the poor test case) so I will cook up something like

Re: [R] rbind with partially overlapping column names

2011-05-15 Thread Ian Gow
That approach relies on df1 and df2 not having overlapping values in b. Slight variation in df2 gives different results: > df1 <- data.frame(a=c("A","A"),b=c("B","B")) > df2 <- data.frame(b=c("B","B"),c=c("c","c")) > merge(df1,df2,all=TRUE) b a c 1 B A c 2 B A c 3 B A c 4 B A c On 5/15/11 11:1

Re: [R] rbind with partially overlapping column names

2011-05-15 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Flowers > Sent: Sunday, May 15, 2011 5:41 PM > To: r-help@r-project.org > Subject: [R] rbind with partially overlapping column names > > Hello, > > I would like to mer

Re: [R] rbind with partially overlapping column names

2011-05-15 Thread Dennis Murphy
Hi: Another way, with a little less typing but using the same principle, is df1$c <- df2$a <- NA rbind(df1, df2) Dennis On Sun, May 15, 2011 at 5:50 PM, Ian Gow wrote: > Hi: > > This is a bit of a kluge, but works for your test case: > >> df2[,setdiff(names(df1),names(df2))] <- NA >> df1[,setd

Re: [R] rbind with partially overlapping column names

2011-05-15 Thread Ian Gow
Hi: This is a bit of a kluge, but works for your test case: > df2[,setdiff(names(df1),names(df2))] <- NA > df1[,setdiff(names(df2),names(df1))] <- NA > df3 <- rbind(df1,df2) > df3 a b c 1 A B 2 A B 3 b c 4 b c -Ian On 5/15/11 7:41 PM, "Jonathan Flowers" wrote: >Hello, > >I would like to

Re: [R] rbind a heterogeneous row

2011-03-22 Thread Henrique Dallazuanna
You need a list object indeed of a vector, try this: rbind(df, dreps = c(rep(list(TRUE), 7), 5, 0)) On Tue, Mar 22, 2011 at 10:12 PM, Alexy Khrabrov wrote: > I have a dataframe with many rows like this: > >> df >                 X1   X2   X3   X4   X5   X6   X7 week         d > sim1 FALSE TRUE T

Re: [R] rbind ing matrices and resetting column numbers

2010-10-14 Thread David Winsemius
On Oct 14, 2010, at 10:40 AM, David Winsemius wrote: On Oct 14, 2010, at 10:31 AM, Maas James Dr (MED) wrote: 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.

Re: [R] rbind ing matrices and resetting column numbers

2010-10-14 Thread David Winsemius
On Oct 14, 2010, at 10:31 AM, Maas James Dr (MED) wrote: 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 su

Re: [R] rbind() overwriting data.frame()

2010-09-06 Thread rajesh j
Also, when I create the data.frame with matrix and try to rbind, I get warnings.. Warning messages: 1: In `[<-.factor`(`*tmp*`, ri, value = "4") : invalid factor level, NAs generated 2: In `[<-.factor`(`*tmp*`, ri, value = "5") : invalid factor level, NAs generated 3: In `[<-.factor`(`*tmp*`, r

Re: [R] rbind() overwriting data.frame()

2010-09-06 Thread rajesh j
But If I do that how will I resize later? On Mon, Sep 6, 2010 at 8:54 PM, ONKELINX, Thierry wrote: > This will give a matrix with 0 rows. > > data.frame(matrix(nrow = 0, ncol = 22, dimnames = list(NULL, > LETTERS[1:22]))) > > But you should avoid growing dataframes is the final dataframe is goin

Re: [R] rbind() overwriting data.frame()

2010-09-06 Thread ONKELINX, Thierry
This will give a matrix with 0 rows. data.frame(matrix(nrow = 0, ncol = 22, dimnames = list(NULL, LETTERS[1:22]))) But you should avoid growing dataframes is the final dataframe is going to be large. You are very likely to get memory problems. It is much to better to create a large enough datafr

Re: [R] rbind() overwriting data.frame()

2010-09-06 Thread Ivan Calandra
Hi again! I'm trying to follow your general goal from your questions today but it's not easy. First, declaring a data.frame of 0 rows is a bad idea. It is much faster to define the length and number of rows from the beginning and to fill it then. Second, I don't know how to do it! What I kn

Re: [R] rbind with different columns

2010-06-21 Thread Daniel Malter
Works wonderfully. I am very happy that I eventually found this post :) Daniel. -- View this message in context: http://r.789695.n4.nabble.com/rbind-with-different-columns-tp907370p2263588.html Sent from the R help mailing list archive at Nabble.com. ___

Re: [R] rbind, data.frame, classes

2010-03-15 Thread Rob Forler
a hah, that works :) simple but sweet, thanks, Rob On Mon, Mar 15, 2010 at 1:59 PM, Henrique Dallazuanna wrote: > Try this: > > do.call(rbind, lapply(list(list1, list2), as.data.frame)) > > On Mon, Mar 15, 2010 at 3:42 PM, Rob Forler wrote: > > Hi, > > > > This has bugged me for a bit. First

Re: [R] rbind, data.frame, classes

2010-03-15 Thread Henrique Dallazuanna
Try this: do.call(rbind, lapply(list(list1, list2), as.data.frame)) On Mon, Mar 15, 2010 at 3:42 PM, Rob Forler wrote: > 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 turnin

Re: [R] rbind with different columns

2009-10-20 Thread Antje
Karl Ove Hufthammer wrote: In article <4addc1d0.2040...@yahoo.de>, niederlein-rs...@yahoo.de says... In every list entry is a data.frame but the columns are only partially the same. If I have exactly the same columns, I could do the following command to combine my data: do.call("rbind", myLis

Re: [R] rbind with different columns

2009-10-20 Thread Ista Zahn
Nice! I was going to recommend merge(merge(myList[[1]], myList[[2]], all=TRUE, sort=FALSE), myList[[3]], all=TRUE, sort=FALSE) but rbind.fill is better. -Ista On Tue, Oct 20, 2009 at 10:05 AM, Karl Ove Hufthammer wrote: > In article <4addc1d0.2040...@yahoo.de>, niederlein-rs...@yahoo.de > says

Re: [R] rbind with different columns

2009-10-20 Thread Karl Ove Hufthammer
In article <4addc1d0.2040...@yahoo.de>, niederlein-rs...@yahoo.de says... > In every list entry is a data.frame but the columns are only partially > the same. If I have exactly the same columns, I could do the following > command to combine my data: > > do.call("rbind", myList) > > but of cour

Re: [R] rbind to array members‏

2009-10-19 Thread RICHARD M. HEIBERGER
>        z <- abind(x[,,1], c(4,5,6),along=0) z is probably not what you want because you aren't using the drop=FALSE argument. See the FAQ 7.5 abind, and arrays in general, are rectangular solids. They are not ragged. For that you need lists. To get something like your request > x > , , 1 >

Re: [R] rbind to array members‏

2009-10-19 Thread Another Oneforyou
(resent as hotmail really cannot format plaintext, but I've just read Tony Plate's message that what I'd like to do might not be possible) > > library(abind) ## array binding I've looked into using abind() but it seems I might not understand it properly. I can build my 2 table array and insert a

Re: [R] rbind to array members

2009-10-19 Thread Tony Plate
Unfortunately, I can't read your examples. Can you repost without the formatting characters which are confusing when rendered in plain text? One thing to keep in mind is that a R array is a regular object -- e.g., if you have a 2 x 3 x 4 array, then if you want to add a row to a slice, you mus

Re: [R] rbind to array members

2009-10-19 Thread Another Oneforyou
<4adbca02.8020...@temple.edu> Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 >=20 > library(abind) ## array binding I've looked into using abind()=2C but it seems I might not understand it pr= operly. I can build my 2 table arra

Re: [R] rbind to array members

2009-10-18 Thread Richard M. Heiberger
library(abind) ## array binding __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible

Re: [R] rbind for a list

2009-09-29 Thread Carlos Hernandez
On Tue, Sep 29, 2009 at 8:05 PM, David Winsemius wrote: > > On Sep 29, 2009, at 1:43 PM, Carlos Hernandez wrote: > > Dear All, >> I´m using the following code: >> >> all1<-gg2[[1]][[1]]; for(i in 1:48){ all1 <- rbind(all1,gg2[[i]][[1]]) } >> > > Looks to me that you would be getting a duplicate c

Re: [R] rbind for a list

2009-09-29 Thread David Winsemius
On Sep 29, 2009, at 1:43 PM, Carlos Hernandez wrote: Dear All, I´m using the following code: all1<-gg2[[1]][[1]]; for(i in 1:48){ all1 <- rbind(all1,gg2[[i]] [[1]]) } Looks to me that you would be getting a duplicate copy of the first matrix, but aside from that what problems are you expe

Re: [R] rbind for a list

2009-09-29 Thread Carlos Hernandez
Thank you for your quick reply! It works perfectly! On Tue, Sep 29, 2009 at 7:51 PM, Henrique Dallazuanna wrote: > Try this; > > do.call(rbind, sapply(gg2, '[', 1)) > > On Tue, Sep 29, 2009 at 2:43 PM, Carlos Hernandez > wrote: > > Dear All, > > I´m using the following code: > > > > all1<-gg2[[1

Re: [R] rbind for a list

2009-09-29 Thread Henrique Dallazuanna
Try this; do.call(rbind, sapply(gg2, '[', 1)) On Tue, Sep 29, 2009 at 2:43 PM, Carlos Hernandez wrote: > Dear All, > I´m using the following code: > > all1<-gg2[[1]][[1]]; for(i in 1:48){ all1 <- rbind(all1,gg2[[i]][[1]]) } > > to create a new matrix that contains all the matrices in a list call

Re: [R] rbind

2009-06-22 Thread Patrick Burns
Now that I've actually read the question, I'm in a better position to answer it. I have no idea how you are getting the results that you show, but you can use 'rownames' to set whatever row names you like. As in: rownames(result) <- 1:6 Pat Patrick Burns wrote: I'm guessing that your 'data'

Re: [R] rbind

2009-06-22 Thread Patrick Burns
I'm guessing that your 'data' and 'data1' are just vectors so your 'rbind' command returns a 2 by 3 matrix. Jim showed you already that: rbind(as.matrix(data), as.matrix(data1)) will probably get you what you are looking for. However, I'm suspicious that just: c(data, data1) will serve you j

Re: [R] rbind

2009-06-21 Thread jim holtman
You need to provide a reproducible example. At least provide an 'str' of your data and preferably the output of 'dput'. I am not sure what you data looks like. works fine for me when using matrices: > data [,1] [1,]5 [2,] 2342 [3,] 33 > data1 [,1] [1,]6 [2,]5 [3,]7 >

Re: [R] rbind help

2009-05-12 Thread James W. MacDonald
Hi Mike, MikSmith wrote: Hi I have a dataset of orientation and elevation in a dataframe which I am plotting in circular. Orientation is on the range 0-360, however I need to reduce this to 0-180 as the values over 180 are not necessarily correct. I can do striae$orientation[striae$orientation

Re: [R] rbind on a list

2009-04-23 Thread David Hajage
Thank you, it is working. David 2009/4/23 Henrique Dallazuanna > Try this: > > lapply(names(col.prop), function(idx)rbind(col.prop[[idx]], n[[idx]])) > > On Thu, Apr 23, 2009 at 7:33 AM, David Hajage wrote: > >> I have two lists (and possibly more): >> >> col.prop <- >> structure(list(B = stru

Re: [R] rbind on a list

2009-04-23 Thread Henrique Dallazuanna
Try this: lapply(names(col.prop), function(idx)rbind(col.prop[[idx]], n[[idx]])) On Thu, Apr 23, 2009 at 7:33 AM, David Hajage wrote: > I have two lists (and possibly more): > > col.prop <- > structure(list(B = structure(c(0.5, 0.5, 0.6, 0.4, 0.556, > 0.444), class = c("

Re: [R] rbind data frames stored in a list

2009-04-22 Thread Dimitri Liakhovitski
Thank you very much, do.call is, of course, much more elegant! Dimitri On Wed, Apr 22, 2009 at 9:58 PM, jim holtman wrote: > 'do.call' is your friend:: > >> a<-data.frame(a=1,b=2,c=3) >> b<-data.frame(a=c(4,7),b=c(5,8),c=c(6,9)) >> c<-data.frame(a=c(10,13,16),b=c(11,14,17),c=c(12,15,18)) >> X<-li

Re: [R] rbind data frames stored in a list

2009-04-22 Thread Dimitri Liakhovitski
Replying to my own post. I found the following solution: full.frame<-as.data.frame(matrix(nrow=0,ncol=3)) names(full.frame)<-c("a","b","c") for(j in 1:length(X)) {full.frame<-rbind(full.frame,X[[j]])} (full.frame) Is there a more elegant solution? Thank you! Dimitri On Wed, Apr 22, 2009 at 9:36

Re: [R] rbind data frames stored in a list

2009-04-22 Thread jim holtman
'do.call' is your friend:: > a<-data.frame(a=1,b=2,c=3) > b<-data.frame(a=c(4,7),b=c(5,8),c=c(6,9)) > c<-data.frame(a=c(10,13,16),b=c(11,14,17),c=c(12,15,18)) > X<-list() > X[[1]]<-a > X[[2]]<-b > X[[3]]<-c > do.call(rbind, X) a b c 1 1 2 3 2 4 5 6 3 7 8 9 4 10 11 12 5 13 14 15 6 16

Re: [R] rbind data frames stored in a list

2009-04-22 Thread Bert Gunter
?do.call ... as in do.call(rbind,X) (A very useful and powerful feature os the S language: Computing on the language. See V&R's "S Programming" for an informative discussion (there may well be others, of course). -- Bert -Original Message- From: r-help-boun...@r-project.org [mailto:r-h

Re: [R] rbind data frames stored in a list

2009-04-22 Thread Marc Schwartz
On Apr 22, 2009, at 8:36 PM, Dimitri Liakhovitski wrote: Hello everyone! I have a list X with 3 elements, each of which is a data frame, for example: a<-data.frame(a=1,b=2,c=3) b<-data.frame(a=c(4,7),b=c(5,8),c=c(6,9)) c<-data.frame(a=c(10,13,16),b=c(11,14,17),c=c(12,15,18)) X<-list() X[[1

Re: [R] rbind: number of columns of result is not a multiple of vector length (arg 1)

2009-02-17 Thread jim holtman
You could 'split' the dataframe and then write out each element: something like x <- split(data.info, data.info$station.id) for (i in names(x)) write.csv(x[[i]], file=paste(i, ".csv", sep="")) On Tue, Feb 17, 2009 at 10:11 PM, CJ Rubio wrote: > > it works perfectly thank you for your help...

Re: [R] rbind: number of columns of result is not a multiple of vector length (arg 1)

2009-02-17 Thread CJ Rubio
it works perfectly thank you for your help what if i want to seperate each stations data and save in a .csv file?? while i'm asking you these i'm also finding some ways to do so.. thank you again. jholtman wrote: > > try using: > > data.info <- rbind(data.info, cbind(station.id, y

Re: [R] rbind: number of columns of result is not a multiple of vector length (arg 1)

2009-02-17 Thread jim holtman
try using: data.info <- rbind(data.info, cbind(station.id, year, date, max.discharge)) On Tue, Feb 17, 2009 at 9:26 PM, CJ Rubio wrote: > > i have the following constructed and running very well,, thanks to Gabor > Grothendieck for his help. > >>data.info <- c("station.id", "year", "date", "max.

Re: [R] rbind for matrices - rep argument

2009-01-07 Thread Gabor Grothendieck
For matrices you can use kronecker: > kronecker(rep(1, 6), data.matrix(Xdf)) [,1] [,2] [,3] [,4] [1,] 1.1 2.1 3.1 4.1 [2,] 1.2 2.2 3.2 4.2 [3,] 1.1 2.1 3.1 4.1 [4,] 1.2 2.2 3.2 4.2 [5,] 1.1 2.1 3.1 4.1 [6,] 1.2 2.2 3.2 4.2 [7,] 1.1 2.1 3.1 4.1 [8,] 1.2 2

Re: [R] rbind for matrices - rep argument

2009-01-07 Thread Patrick Burns
Ben Bolker wrote: Dimitris Rizopoulos erasmusmc.nl> writes: you can use indexing, e.g., mat <- matrix(rnorm(20), 4, 5) mat mat[rep(1:nrow(mat), 3), ] I hope it helps. Best, Dimitris or matrix trickery: z <- as.data.frame(matrix(sample(1:9,20,replace=TRUE),nrow=4)) matrix(rep(a

Re: [R] rbind for matrices - rep argument

2009-01-07 Thread Ted Harding
On 07-Jan-09 15:22:57, Niccolò Bassani wrote: > 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,]12345

Re: [R] rbind for matrices - rep argument

2009-01-07 Thread Carlos J. Gil Bellosta
On Wed, 2009-01-07 at 16:22 +0100, Niccolò Bassani wrote: > 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,]12

Re: [R] rbind for matrices - rep argument

2009-01-07 Thread Ben Bolker
Dimitris Rizopoulos erasmusmc.nl> writes: > > you can use indexing, e.g., > > mat <- matrix(rnorm(20), 4, 5) > > mat > mat[rep(1:nrow(mat), 3), ] > > I hope it helps. > > Best, > Dimitris or matrix trickery: z <- as.data.frame(matrix(sample(1:9,20,replace=TRUE),nrow=4)) matrix(rep(as.mat

Re: [R] rbind for matrices - rep argument

2009-01-07 Thread Henrique Dallazuanna
Try this: m[rep(seq_len(nrow(m)), 3),] On Wed, Jan 7, 2009 at 1:22 PM, Niccolò Bassani wrote: > 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]

Re: [R] rbind for matrices - rep argument

2009-01-07 Thread Dimitris Rizopoulos
you can use indexing, e.g., mat <- matrix(rnorm(20), 4, 5) mat mat[rep(1:nrow(mat), 3), ] I hope it helps. Best, Dimitris Niccolò Bassani wrote: 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 quest

Re: [R] rbind() problem

2008-06-13 Thread Tobias Verbeke
Hi array (?), Hi, I would like to rbind 2 data frames. They both some common column names, but also some unique column names each, is there any simple function that rbind these 2 data frames with filling NAs for those columns of unique names? You can use the reshape package by Hadley Wickham

Re: [R] Rbind-ing a list into one item

2007-12-26 Thread Bert Gunter
TED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, December 26, 2007 1:37 PM To: r-help@r-project.org; Kondamani, Arjun (GMI - NY Corporate Bonds) Subject: Re: [R] Rbind-ing a list into one item >From: "Kondamani, Arjun (GMI - NY Corporate Bonds)" <[EMA

Re: [R] Rbind-ing a list into one item

2007-12-26 Thread Andrew Robinson
Hi Arjun, try do.call() Cheers Andrew On Wed, Dec 26, 2007 at 04:23:51PM -0500, Kondamani, Arjun (GMI - NY Corporate Bonds) wrote: > 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=vec

Re: [R] Rbind-ing a list into one item

2007-12-26 Thread markleeds
>From: "Kondamani, Arjun (GMI - NY Corporate Bonds)" <[EMAIL PROTECTED]> >Date: 2007/12/26 Wed PM 03:23:51 CST >To: r-help@r-project.org >Subject: [R] Rbind-ing a list into one item try do.call(rbind,res) >Hi, > >I am doing the following: > >1. I have a list of files.. Files1=list.files("some >d