Re: [R] Merge and replace data

2023-09-07 Thread Richard O'Keefe
I'm a little confused, because the sample code does something that none of the suggestions does. x1 <- c(116,0,115,137,127,0,0) x2 <- c(0,159,0,0,0,159,127) [You] want : xx <- c(116,115,137,127,159, 127) Assuming that there should have been two copies of 159 in xx, this is xx <- c(x1[x1 != 0], x2[

Re: [R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Thank you for the general code. Really appreciate it. On Tue, Sep 5, 2023 at 7:59 PM Eric Berger wrote: > As Duncan points out, ifelse() provides a more general approach than > the specific pmax(). > > Even more generally, you might want to consider the apply() function > (and its relatives sap

Re: [R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Thank you for the general code. Really appreciate it. On Tue, Sep 5, 2023 at 7:45 PM Duncan Murdoch wrote: > On 05/09/2023 4:55 a.m., roslinazairimah zakaria wrote: > > Hi all, > > > > I have these data > > > > x1 <- c(116,0,115,137,127,0,0) > > x2 <- c(0,159,0,0,0,159,127) > > > > I want : xx <

Re: [R] Merge and replace data

2023-09-05 Thread Eric Berger
As Duncan points out, ifelse() provides a more general approach than the specific pmax(). Even more generally, you might want to consider the apply() function (and its relatives sapply(), lapply(), ...) For example apply(cbind(x1,x2), MAR=1, max) In the above statement, x1 and x2 are combined i

Re: [R] Merge and replace data

2023-09-05 Thread Duncan Murdoch
On 05/09/2023 4:55 a.m., roslinazairimah zakaria wrote: Hi all, I have these data x1 <- c(116,0,115,137,127,0,0) x2 <- c(0,159,0,0,0,159,127) I want : xx <- c(116,115,137,127,159, 127) I would like to merge these data into one column. Whenever the data is '0' it will be replaced by the value

Re: [R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Thank you very much for your help. On Tue, Sep 5, 2023 at 6:39 PM Rui Barradas wrote: > Às 09:55 de 05/09/2023, roslinazairimah zakaria escreveu: > > Hi all, > > > > I have these data > > > > x1 <- c(116,0,115,137,127,0,0) > > x2 <- c(0,159,0,0,0,159,127) > > > > I want : xx <- c(116,115,137,127

Re: [R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Thank you very much for your help. On Tue, Sep 5, 2023 at 6:12 PM Eric Berger wrote: > xx <- pmax(x1,x2) > > On Tue, Sep 5, 2023 at 11:56 AM roslinazairimah zakaria > wrote: > > > > Hi all, > > > > I have these data > > > > x1 <- c(116,0,115,137,127,0,0) > > x2 <- c(0,159,0,0,0,159,127) > > > >

Re: [R] Merge and replace data

2023-09-05 Thread Rui Barradas
Às 09:55 de 05/09/2023, roslinazairimah zakaria escreveu: Hi all, I have these data x1 <- c(116,0,115,137,127,0,0) x2 <- c(0,159,0,0,0,159,127) I want : xx <- c(116,115,137,127,159, 127) I would like to merge these data into one column. Whenever the data is '0' it will be replaced by the valu

Re: [R] Merge and replace data

2023-09-05 Thread Eric Berger
xx <- pmax(x1,x2) On Tue, Sep 5, 2023 at 11:56 AM roslinazairimah zakaria wrote: > > Hi all, > > I have these data > > x1 <- c(116,0,115,137,127,0,0) > x2 <- c(0,159,0,0,0,159,127) > > I want : xx <- c(116,115,137,127,159, 127) > > I would like to merge these data into one column. Whenever the da

Re: [R] Merge with closest (not equal) time stamps

2023-08-24 Thread Naresh Gurbuxani
Thanks for your suggestion. I have just returned from a vacation and started catching up on my emails. Rolling join is an elegant and most suitable solution for my tasks. I invested some time in learning data.table package. The vignette on secondary indices and auto indexing refers to anoth

Re: [R] Merge with closest (not equal) time stamps

2023-08-09 Thread Hadley Wickham
It sounds like you might want a rolling join, e.g. https://dplyr.tidyverse.org/reference/join_by.html#rolling-joins. (And data.table has similar functionality which inspired dplyr) Hadley On Mon, Aug 7, 2023 at 9:32 PM Naresh Gurbuxani wrote: > > > I have two dataframes, each with a column for

Re: [R] Merge with closest (not equal) time stamps

2023-08-08 Thread Enrico Schumann
On Mon, 07 Aug 2023, Naresh Gurbuxani writes: > I have two dataframes, each with a column for timestamp. I want to > merge the two dataframes such that each row from first dataframe > is matched with the row in the second dataframe with most recent but > preceding timestamp. Here is an example. >

Re: [R] Merge with closest (not equal) time stamps

2023-08-08 Thread Naresh Gurbuxani
I was able to adapt your solution using packages with which I am more familiar. myres2 <- merge(option.trades, stock.trades, by = "timestamp", all = TRUE) myres2[,"stock.timestamp"] <- ifelse(is.na(myres2$stock.price), NA, myres2$timestamp) myres2$stock.timestamp <- as.POSIXct(myres2$stock.time

Re: [R] Merge with closest (not equal) time stamps

2023-08-08 Thread Eric Berger
Hi Naresh, Perhaps the below is faster than your approach library(dplyr) library(tidyr) merge(option.trades, stock.trades, by="timestamp", all=TRUE) |> dplyr::arrange(timestamp) |> dplyr::mutate(stock.timestamp = as.POSIXct(ifelse(is.na(option.price), timestamp, NA))) |> tidyr::fill(stock.pr

Re: [R] Merge column with characters

2021-11-19 Thread ROSLINAZAIRIMAH BINTI ZAKARIA .
Hi Jim and all, All functions worked beautifully. I really appreciate your help. *Thank you and best regards.* On Fri, Nov 19, 2021 at 4:26 AM Jim Lemon wrote: > Hi RosalinaZakaria, > Talk about using a sledgehammer to crack a nut. In your example the > two objects are character vectors. Ho

Re: [R] Merge column with characters

2021-11-18 Thread Jim Lemon
Hi RosalinaZakaria, Talk about using a sledgehammer to crack a nut. In your example the two objects are character vectors. How about: dt_comb1gd <-paste0(dtpaigd,dtpmgd) Jim On Fri, Nov 19, 2021 at 2:15 AM ROSLINAZAIRIMAH BINTI ZAKARIA . wrote: > > Dear all, > > I try to merge two columns consi

Re: [R] Merge column with characters

2021-11-18 Thread Rui Barradas
Hello, Use an index giving the "" positions. i <- nchar(dtpmgd) == 0L dtpmgd[i] <- dtpaigd[i] Or, in one line, dtpmgd[nchar(dtpmgd) == 0L] <- dtpaigd[nchar(dtpmgd) == 0L] Hope this helps, Rui Barradas Às 07:02 de 18/11/21, ROSLINAZAIRIMAH BINTI ZAKARIA . escreveu: Dear all, I try t

Re: [R] Merge column with characters

2021-11-18 Thread Micha Silver
On 18/11/2021 09:02, ROSLINAZAIRIMAH BINTI ZAKARIA . wrote: Dear all, I try to merge two columns consisting of characters using the 'coalesce' function from dplyr package. However, two data still have not merged, data no. 124 1nd 143. Any help is very much appreciated. I provide the data as fo

Re: [R] Merge the data from multiple text files

2019-01-07 Thread David L Carlson
A and B) and not(B). David C -Original Message- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: Monday, January 7, 2019 11:04 AM To: Priya Arasu ; Priya Arasu via R-help ; David L Carlson ; David Winsemius ; r-help@r-project.org Subject: Re: [R] Merge the data from multiple

Re: [R] Merge the data from multiple text files

2019-01-07 Thread Jeff Newmiller
quot;(A and C)" "not(D)"  > >$C >[1] "D" > >> TF.and <- lapply(TF.list, paste, collapse=" and ") >> TF.final <- lapply(names(TF.and), function(x) paste(x, "=", >TF.and[[x]])) >> TF.final <- do.call(rbind, TF.final) >>

Re: [R] Merge the data from multiple text files

2019-01-07 Thread Priya Arasu via R-help
t; [2,] "B = (A and C) and not(D)" [3,] "C = D" > write(TF.final, file="TF.output.txt") The text file "TF.output.txt" contains the three lines. -- David L. Carlson Department of Anthropology Texas A&M Unive

Re: [R] Merge the data from multiple text files

2019-01-05 Thread David L Carlson
[1,] "A = (D and E) and not(B or C)" [2,] "B = (A and C) and not(D)" [3,] "C = D" > write(TF.final, file="TF.output.txt") The text file "TF.output.txt" contains the three lines. -- David L. Ca

Re: [R] Merge the data from multiple text files

2019-01-05 Thread David Winsemius
On 1/5/19 7:28 AM, Priya Arasu via R-help wrote: I have multiple text files, where each file has Boolean rules. Example of my text file 1 and 2 Text file 1: A = not(B or C) B = A and C C = D Text file 2: A = D and E B = not(D) I want to merge the contents in text file as follows A = not(B or C

Re: [R] merge two data frame based on equal and unequal comparisons

2018-04-18 Thread Ding, Yuan Chun
HI All, I found that other R users experienced the same problem when using sqldf package. An expert provided solution, adding "method="raw" at the end as below, one or more of the columns in my data.frame are of class "AsIs" ( I don't know what it is) . When sqldf retrieves the result from SQL

Re: [R] Merge by Range in R

2017-09-04 Thread jim holtman
Have you tried 'foverlaps' in the data.table package? Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Mon, Sep 4, 2017 at 8:31 AM, Mohammad Tanvir Ahamed via R-help < r-help@r-project.org> wrote: > Hi, >

Re: [R] Merge list element by name

2017-04-13 Thread David Winsemius
> On Apr 13, 2017, at 7:56 AM, Mohammad Tanvir Ahamed via R-help > wrote: > > Hi, > I have a list like > kk<- list (a = 1:5, b = 6:10, c = 4:11) > > Now i want to merger (Union) the list element "a" and "c" by name . > > My expected outcome is > kk1<- list(a_c = 1:11, b = 6:10) > > > I c

Re: [R] Merge selected list element by name

2017-04-13 Thread Bert Gunter
list(a_c = 1:11, b = 6:10) just to show by > expected outcome. But i am expecting the resulting code will naming "a_c" by > itself also. > Hope i can make clear about problem. > > > > > Tanvir Ahamed > Göteborg, Sweden | mashra...@yahoo.com > > > >

Re: [R] Merge selected list element by name

2017-04-13 Thread Mohammad Tanvir Ahamed via R-help
rsday, 13 April 2017, 18:37 Subject: Re: [R] Merge selected list element by name Hello, There's no need to send the same question twice, we've got it at the first try. Maybe I don't understand but is this it? kk1 <- list(a_c = union(kk$a, kk$c), b = kk$b) kk1 $a_c [1] 1 2

Re: [R] Merge selected list element by name

2017-04-13 Thread Rui Barradas
Hello, There's no need to send the same question twice, we've got it at the first try. Maybe I don't understand but is this it? kk1 <- list(a_c = union(kk$a, kk$c), b = kk$b) kk1 $a_c [1] 1 2 3 4 5 6 7 8 9 10 11 $b [1] 6 7 8 9 10 Hope this helps, Rui Barradas Em 13-04-2017 1

Re: [R] Merge data by coordinates

2016-10-18 Thread Michal Kubista
Dear Milu, If your objective is to match the places from one table to the nearest place in the second table, you can generally use knn algorithm for 1 nearest neighbourhood. But please, check what David suggests first. Best regards, Michal 2016-10-16 19:24 GMT+02:00 David Winsemius : > > > On Oc

Re: [R] Merge data by coordinates

2016-10-16 Thread David Winsemius
> On Oct 16, 2016, at 6:32 AM, Miluji Sb wrote: > > Dear all, > > I have two dataframe 1 by latitude and longitude but they always do not > match. Is it possible to merge them (e.g. nearest distance)? > > # Dataframe 1 > structure(list(lat = c(54L, 55L, 51L, 54L, 53L, 50L, 47L, 51L, > 49L, 54L

Re: [R] Merge several datasets into one

2016-07-01 Thread Lida Zeighami
Hi Lily, I think below codes can work: f<- list.files("D:/output/test/your folde rname",full.names=TRUE,recursive=TRUE) files<- grep(".csv", f) files_merge<- data.frame() for (i in 1:length(f[files])){ data<- read.csv(file=f[files][i],header=TRUE, sep=",") files_merge<- rbind(files_merge,

Re: [R] Merge several datasets into one

2016-07-01 Thread ruipbarradas
Hello, Maybe something like this. fls <- list.files(pattern = "*.csv") dat.list <- lapply(fls, read.csv) dat <- do.call(rbind, dat.list) Hope this helps, Rui Barradas   Citando lily li : > Hi R users, > > I'd like to ask that how to merge several datasets into one in R? I put > these csv file

Re: [R] Merge several datasets into one

2016-06-30 Thread Lists
Lily Li wrote : I think you are going to have to give us some more detail. What commands did you execute? what are the names of the .csv files in your directory? Can you read one of them as asingle read.csv? > Hi R users, > > I'd like to ask that how to merge several datasets into one in R? I

Re: [R] Merge several datasets into one

2016-06-30 Thread Bert Gunter
Lily: If you mean that you have several csv files in a directory/folder on your computer and you are using lapply() to do something with them, then you do not have a clue about how R works and you need to go through some tutorials to learn. There are many good ones on the web. Some recommendations

Re: [R] Merge sort

2016-04-20 Thread Duncan Murdoch
On 20/04/2016 7:38 AM, Gaston wrote: I indeed used is.na() to check length, as I was not sure weather lenght() was a simple query or would go through the whole vector to count the elements. length() is a simple query, and is very fast. The other problem in your approach (which may not be a pr

Re: [R] Merge sort

2016-04-20 Thread Gaston
I indeed used is.na() to check length, as I was not sure weather lenght() was a simple query or would go through the whole vector to count the elements. So to sum up, function calls are expensive, therefore recursion should be avoided, and growing the size of a vector (which is probably reass

Re: [R] Merge sort

2016-04-19 Thread Duncan Murdoch
On 19/04/2016 3:39 PM, Gaston wrote: Hello everyone, I am learning R since recently, and as a small exercise I wanted to write a recursive mergesort. I was extremely surprised to discover that my sorting, although operational, is deeply inefficient in time. Here is my code : merge <- function(

Re: [R] merge small clusters in R

2016-03-19 Thread Boris Steipe
This is not a well defined question, until your notions of "small" and "nearest" are defined. In your specific example rect.hclust(hc, k = 3, border = 2:5) ... will do what you are asking for. This is not likely to work in the general case - imagine that your cluster of size two only meets t

Re: [R] merge xts objects with different data types ?

2015-09-03 Thread Jeff Newmiller
The root of your problems lie in your assumption that xts variables act like data frames. Instead they are matrices with an index attribute. All values in a matrix must be of the same storage mode. You might want to investigate the data.table package. It is not a time series object but you can

Re: [R] merge xts objects with different data types ?

2015-09-03 Thread ce
c" 2015-09-06 "def" 2015-09-07 "abc" -Original Message- From: "Joshua Ulrich" [josh.m.ulr...@gmail.com] Date: 09/03/2015 09:43 PM To: "ce" CC: "R-Help" Subject: Re: [R] merge xts objects with different data types ? On Thu, Se

Re: [R] merge xts objects with different data types ?

2015-09-03 Thread Joshua Ulrich
On Thu, Sep 3, 2015 at 7:40 PM, ce wrote: > > Hello > > Let's say some questions about merging xts variables : > > a<- xts("abc", Sys.Date()) > b <- xts("def", Sys.Date()) > c <- xts(1, Sys.Date()) > >> merge(a,b) >a b > 2015-09-03 "abc" "def" >> merge(a,b,c) > a b c

Re: [R] merge: right set overwrite left set

2015-07-13 Thread aldi
Thank you Jeff, Your solutions have two great aspects: a) you provide a different approach by using reshape2 syntax / tidyr, and b) the concern that it is better to update x.HHu.map with y.HHo.map, without overwriting x.HHu.map with NA from y.HHo.map, thus keeping intact the old value(s). That i

Re: [R] merge: right set overwrite left set

2015-07-13 Thread aldi
Thank you Ista, Your solution is smart, by sub-setting from x.HHu.map data only "HHid", "position" as indices (because they are unique) for the merge, and any extra columns in x.HHu.map that are not present in y.HHo,map, thus when the merge is done with option all=T, will work among the two sets

Re: [R] merge: right set overwrite left set

2015-07-12 Thread Jeff Newmiller
I get confused by your use of the position map table. If I follow your description toward your desired result, I take a different route that makes sense to me. Perhaps it will make sense to you as well. The key idea is to make individual comparisons of the values for each combination of HHid an

Re: [R] merge: right set overwrite left set

2015-07-12 Thread Ista Zahn
I think this does what you want: ## find idiv coloumns in x.HHu.map that don't exist in y.HHo.map x.HHu.map <- x.HHu.map[ c("HHid", "position", names(x.HHu.map)[ !names(x.HHu.map) %in% names(y.HHo.map)] )] ## merge, adding extra column from x.HHu

Re: [R] merge function

2015-06-01 Thread John Kane
Exactly what I thought too the first time I read ?merge. R sometimes has its own approach. John Kane Kingston ON Canada > -Original Message- > From: r-help@r-project.org > Sent: Mon, 1 Jun 2015 14:47:07 + (UTC) > To: li...@dewey.myzen.co.uk, r-help@r-project.org >

Re: [R] merge function

2015-06-01 Thread Bert Gunter
You do not appear to understand what merge() does. Go through the worked examples in ?merge so that you do. FWIW, I would agree that the Help file is cryptic and difficult to understand. Perhaps going through a tutorial on database "join" operations might help. Cheers, Bert Bert Gunter "Data is

Re: [R] merge function

2015-06-01 Thread carol white via R-help
I understood that by would take the intersection of names(x) and names(y), names(x) being the column names of x and names(y), column names of y. if x has 5 col and the col names of x are col1, col2... col5 and y has 3 col and their names are col1, col2, col3, I thought that the merged data set wi

Re: [R] merge function

2015-06-01 Thread Michael Dewey
On 01/06/2015 14:46, carol white via R-help wrote: Hi,By default the merge function should take the intersection of column names (if this is understood from by = intersect(names(x), names(y)), Dear Carol The by parameter specifies which columns are used to merge by. Did you understand it t

Re: [R] merge function

2015-06-01 Thread John Kane
> Sent: Mon, 1 Jun 2015 06:29:41 -0800 > To: wht_...@yahoo.com, r-help@r-project.org > Subject: RE: [R] merge function > > As Burt says it is not exactly clear what you want but is something like > this what you are looking for? > > dat1 <- data.frame(aa = c

Re: [R] merge function

2015-06-01 Thread John Kane
As Burt says it is not exactly clear what you want but is something like this what you are looking for? dat1 <- data.frame(aa = c("a", "b", "c"), bb = 1:3) dat2 <- data.frame(xx = c("b", "c", "d"), yy = 3:1) merge(dat1, dat2, by.x = "aa", by.y = "xx") For further reference here are some sugg

Re: [R] merge function

2015-06-01 Thread Bert Gunter
1. Please read and follow the posting guide. 2. Reproducible example? (... at least I don't understand what you mean) 3. Plain text, not HTML. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Mon,

Re: [R] Merge List element by name

2015-03-07 Thread Jeff Newmiller
This would be a perfect time for you to use best practices to convey what you have to us [1]... most specifically, posting using plain text will keep your code from getting munged up, and using dput to provide an unambiguous form we can put into our R sessions. [1] http://stackoverflow.com/que

Re: [R] merge 2 data.frames in dependence of 2 values

2014-11-13 Thread Michael Dewey
On 13/11/2014 14:02, Matthias Weber wrote: Hello togehter, i have a little problem. Maybe anyone can help me. I think you might find ?merge enlightening Indeed given that the word merge occurs in your subject line and your text it is surprising you have not already found it. I have 2 d

Re: [R] merge 2 data.frames in dependence of 2 values

2014-11-13 Thread William Dunlap
merge(df1, df2, all=TRUE) Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Nov 13, 2014 at 6:02 AM, Matthias Weber < matthias.we...@fntsoftware.com> wrote: > Hello togehter, > > i have a little problem. Maybe anyone can help me. > > I have 2 data.frames, which look like as follows: > First:

Re: [R] merge 2 data.frames in dependence of 2 values

2014-11-13 Thread Rui Barradas
Hello, See ?merge, in particular the argument 'all'. dat1 <- read.table(text = " NAMEMONTH BONUS 1 Andy 2014-10 100 2 Pete 2014-10200 3 Marc2014-10300 4 Andy2014-11400 ", header = TRUE, stringsAsFactors = FALSE)

Re: [R] merge coefficients from a glmlist of models

2014-10-28 Thread Michael Friendly
On 10/28/2014 12:13 PM, John Fox wrote: Hi Michael, How about this? That's perfect! And more general than I had hoped for. You probably used mindreader() :-) -Michael coef.glmlist <- function(object, result=c("list", "matrix", "data.frame"), ...){ result <- match.arg(result) coe

Re: [R] merge coefficients from a glmlist of models

2014-10-28 Thread John Fox
Hi Michael, How about this? coef.glmlist <- function(object, result=c("list", "matrix", "data.frame"), ...){ result <- match.arg(result) coefs <- lapply(object, coef) if (result == "list") return(coefs) coef.names <- unique(unlist(lapply(coefs, names))) n.mods <- length(objec

Re: [R] Merge of the rows by finding the sum of the rows

2014-10-23 Thread Rui Barradas
Hello, Try aggregate(Rain ~ Year + Month, data = dat, FUN = sum) Hope this helps, Rui Barradas Em 23-10-2014 01:29, Hafizuddin Arshad escreveu: Dear R users, Can someone help me on this? I would like to find the sum of the Rain if the Month appears more than once. For example in row 3 and

Re: [R] merge by time, certain value if 5 min before and after an "event"

2014-10-04 Thread Dagmar
Thank you Jean, Petr, Terry, William and everyone else who thought about my problem. It is sooo good that this mailing list exists! I solved my problem using Petr's suggestion, that didn't seem so complicated and worked fine for me. Thanks again and have a great weekend, Dagmar Am 02.10.2014

Re: [R] merge by time, certain value if 5 min before and after an "event"

2014-10-03 Thread William Dunlap
Hi Terry, Some of that combination of sort() and approx() can be done by findInterval(), which may be quick enough that you don't need the 'thinning' part of the code. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 3, 2014 at 6:05 AM, Therneau, Terry M., Ph.D. wrote: > I've attached

Re: [R] merge by time, certain value if 5 min before and after an "event"

2014-10-03 Thread PIKAL Petr
our mydata and use na.locf to fill gaps you should get desired result. Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Dagmar > Sent: Thursday, October 02, 2014 11:25 PM > Cc: R help > Subject: Re: [R]

Re: [R] merge by time, certain value if 5 min before and after an "event"

2014-10-03 Thread PIKAL Petr
e.g. by ?complete.cases Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Adams, Jean > Sent: Thursday, October 02, 2014 11:38 PM > To: Dagmar > Cc: R help > Subject: Re: [R] merge by time, certain va

Re: [R] merge by time, certain value if 5 min before and after an "event"

2014-10-02 Thread Adams, Jean
Thanks, Dagmar. So, shouldn't row 3 with a time of 09:51:01 be "low" and not "high"? Jean On Thu, Oct 2, 2014 at 4:25 PM, Dagmar wrote: > Dear Jean and all, > > I want all lines to be "low", but during times 9:55 - 10:05 a.m (i.e. a > timespan of 10 min) I want them to be "high". > In my real

Re: [R] merge by time, certain value if 5 min before and after an "event"

2014-10-02 Thread Dagmar
Dear Jean and all, I want all lines to be "low", but during times 9:55 - 10:05 a.m (i.e. a timespan of 10 min) I want them to be "high". In my real data "low" and "high" refer to "lowtide" and "hightide" in the waddensea and I want to assign the location of my animal at the time it was taken to

Re: [R] merge by time, certain value if 5 min before and after an "event"

2014-10-02 Thread Adams, Jean
Dagmar, Can you explain more fully why rows 1, 2, and 5 in your result are "low" and rows 3 and 4 are "high"? It is not clear to me from the information you have provided. > result[c(1, 2, 5), ] Timestamp location Event 1 24.09.2012 09:05:011 low 2 24.09.2012 09:49:50

Re: [R] Merge rows

2014-07-14 Thread David Stevens
Cautionary note on the solution below. Be sure the 'sndr' is either factor or character because, if sndr is numeric, as the list is populated, R will fill in non-adjacent list items with NULLs, leaving a list with many empty entries. So, the modified line is newdat[[as.character(vnam)]]<

Re: [R] Merge rows

2014-07-12 Thread David Stevens
This is a (very) slightly modified version of Jim's reply that takes the sender's email our of the list element and uses it as the name so it can be accessed as newdat$'senders email' or newdat[['senders email']] newdat<-list() for(sndr in unique(rdvdf$sender)) { newvec<- as.character(unique

Re: [R] Merge rows

2014-07-12 Thread Jim Lemon
On Fri, 11 Jul 2014 12:19:39 PM Ryan de Vera wrote: > Hello all, > > I have a data frame filled with senders and recipients. Some of the senders > have multiple rows with different recipients and I want to merge those > rows. For example I have > > a...@email.com b...@email.com > a...@email

Re: [R] Merge rows

2014-07-11 Thread Sarah Goslee
Hi John, I don't think your x2 is right, but who knows? One possible approach would be: R> lapply(split(x2$recipients, unique(x2$sender)), paste, collapse=", ") $`a...@email.com` [1] "b...@email.com, f...@email.com" $`r...@email.com` [1] "c(\"c...@email.com\", \"d...@email.com\"), h...@email.co

Re: [R] Merge rows

2014-07-11 Thread Sarah Goslee
Hi Ryan, We can't tell from your example what structure your original data are in, nor what your output is intended to look like, or for that matter how you got from one to the other. Please don't post in HTML because it gets mangled! Using dput() to provide your example data is the best thing, b

Re: [R] merge question

2014-06-30 Thread Dr Eberhard W Lisse
Rolf, I hear you. But, after reflection, ie I looked at my situation again, it is great :-)-O el Sent from Dr Lisse's iPad mini > On Jun 30, 2014, at 0:48, Rolf Turner wrote: > > >> On 30/06/14 10:32, Dr Eberhard W Lisse wrote: >> >> Thanks, >> >> I then set NA to 0, and can do the sutr

Re: [R] merge question

2014-06-29 Thread Dr Eberhard W Lisse
Thank you very much. el On 2014-06-30, 00:48 , Rolf Turner wrote: > > On 30/06/14 10:32, Dr Eberhard W Lisse wrote: > >> Thanks, >> >> I then set NA to 0, and can do the sutraction, >> >> great. > > Not so great. I haven't gone through the issues underlying this post, > but replacing NA by 0

Re: [R] merge question

2014-06-29 Thread Rolf Turner
On 30/06/14 10:32, Dr Eberhard W Lisse wrote: Thanks, I then set NA to 0, and can do the sutraction, great. Not so great. I haven't gone through the issues underlying this post, but replacing NA by 0 will almost surely yield nonsense. "Missing" is ***not*** the same thing as "zero". Pr

Re: [R] merge question

2014-06-29 Thread Dr Eberhard W Lisse
Thanks, I then set NA to 0, and can do the sutraction, great. el On 2014-06-29, 22:32 , Michael Peng wrote: > you can get a new data frame by > merge(qpiso, qplegit, all.x = TRUE, all.y = TRUE, by = "iso" ) > Take the subtraction on the new data frame. > > > > > 2014-06-29 11:24 GMT-05:00

Re: [R] merge question

2014-06-29 Thread Michael Peng
you can get a new data frame by merge(qpiso, qplegit, all.x = TRUE, all.y = TRUE, by = "iso" ) Take the subtraction on the new data frame. 2014-06-29 11:24 GMT-05:00 Dr Eberhard Lisse : > I have two data frames like so > > > qpiso > iso requests > 1A1 20 > 2A2 199 > 3

Re: [R] merge question

2014-06-29 Thread Jeff Newmiller
If you really prefer solution code, then provide reproducible example code as the footer requests. Use ?merge with the all.x=TRUE parameter, and then perform your calculations on the resulting combined data frame, using ?ifelse and ?is.na as needed. --

Re: [R] Merge two vectors into one

2014-03-24 Thread Tham Tran
Many thank for all your answers. it has helped me save time -- View this message in context: http://r.789695.n4.nabble.com/Merge-two-vectors-into-one-tp4687361p4687447.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.

Re: [R] Merge two vectors into one

2014-03-24 Thread Greg Snow
Just to satisfy my curiosity: > library(microbenchmark) > > a <- 1:10 > b <- 101:110 > > microbenchmark( + m1=as.vector( rbind(a,b) ), + m2=c( rbind(a,b) ), + m3=as.vector( matrix(c(a,b), nrow=2, byrow=TRUE) ), + m4={x <- integer(length(a)*2); x[c(TRUE,FALSE)] <- a; x[c(FALSE,TRUE)] <- b; x}, + m5

Re: [R] Merge two vectors into one

2014-03-24 Thread David Winsemius
On Mar 22, 2014, at 3:22 PM, Tham Tran wrote: > Dear R users, > > Given two vectors x and y > a=1 2 3 > b=4 5 6 > > i want to combine them into a single vector z as 1 4 2 5 3 6 > > Thanks for your help Searching Stackoverflow for [r] interleave produced this idea fron @Arun, which I think i

Re: [R] Merge two vectors into one

2014-03-24 Thread Lisa S
He wants a[1] b[1] a[2] b[2] a[3] b[3] I think you can do: x = as.vector(rbind(a, b)) On Mon, Mar 24, 2014 at 2:39 PM, Frans Marcelissen < fransiepansiekever...@gmail.com> wrote: > Why not simply > > > a<-1:3 > > b<-4:5 > > c(a,b) > [1] 1 2 3 4 5 > > > 2014-03-22 23:22 GMT+01:00 Tham Tran : >

Re: [R] Merge two vectors into one

2014-03-23 Thread Frans Marcelissen
Why not simply > a<-1:3 > b<-4:5 > c(a,b) [1] 1 2 3 4 5 2014-03-22 23:22 GMT+01:00 Tham Tran : > Dear R users, > > Given two vectors x and y > a=1 2 3 > b=4 5 6 > > i want to combine them into a single vector z as 1 4 2 5 3 6 > > Thanks for your help > > Tham > > > > -- > View this message in c

Re: [R] Merge two vectors into one

2014-03-23 Thread Rolf Turner
On 24/03/14 08:37, David Winsemius wrote: On Mar 22, 2014, at 3:22 PM, Tham Tran wrote: Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single vector z as 1 4 2 5 3 6 One way: c( matrix(c(a,b), nrow=2, byrow=TRUE) ) It is more perspicuous to use

Re: [R] Merge two vectors into one

2014-03-23 Thread David Winsemius
On Mar 22, 2014, at 3:22 PM, Tham Tran wrote: > Dear R users, > > Given two vectors x and y > a=1 2 3 > b=4 5 6 > > i want to combine them into a single vector z as 1 4 2 5 3 6 One way: c( matrix(c(a,b), nrow=2, byrow=TRUE) ) Leaving in the usual footer because Nabble's interface usually o

Re: [R] Merge two vectors into one

2014-03-22 Thread arun
Hi, May be this helps: a <- 1:3  b <- 4:6  z <- as.vector(rbind(a,b))  z #[1] 1 4 2 5 3 6 #or z1 <- setNames(c(a,b),rep(seq_along(a),2)) z1 <- as.vector(z1[order(names(z1))]) z1 #[1] 1 4 2 5 3 6 A.K. Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a sin

Re: [R] Merge two data frames on date field

2014-02-07 Thread arun
Hi,You haven't provided any example dataset.  set.seed(42)  dat1 <- data.frame(dates=seq(as.POSIXct("2009-01-01 00:00:00",format="%Y-%m-%d %H:%M:%S"),by= '12 hour', length=12),Field1=rnorm(12),Field2=LETTERS[1:12]) set.seed(395)  dat2 <- data.frame(dates=seq(as.POSIXct("2009-01-01 00:00:00",for

Re: [R] Merge and specify column output order

2014-01-15 Thread arun
Hi, It would be better to post a reproducible example. set.seed(42)  df1 <- cbind(as.data.frame(matrix(sample(60,40,replace=TRUE),ncol=4)),date=seq(as.Date("2013-05-10"),length.out=10,by=1)) colnames(df1)[-5] <- paste0("mod",1:4)  set.seed(14)  df2 <- data.frame(obs=1:20,wy=sample(12,20,replac

Re: [R] Merge xts and Return.portfolio

2013-11-15 Thread Simone Medori
Thanks Simone > Il giorno 15/nov/2013, alle ore 15:30, Joshua Ulrich > ha scritto: > >> On Fri, Nov 15, 2013 at 6:32 AM, Simone Medori wrote: >> Hi, >> I'm triyng to merge two xts time series objects, one of them is from >> Return.portfolio (PerformanceAnalytics). >> >> Despite the merging

Re: [R] Merge xts and Return.portfolio

2013-11-15 Thread Joshua Ulrich
On Fri, Nov 15, 2013 at 6:32 AM, Simone Medori wrote: > Hi, > I'm triyng to merge two xts time series objects, one of them is from > Return.portfolio (PerformanceAnalytics). > > Despite the merging xts objects have the same indexes, the merged object > shows extra lines at the day before of ever

Re: [R] merge multi part polygons

2013-09-11 Thread Bert Gunter
I would suggest you post this on the r-sig-ecology or r-sig-geo lists. These seem both more relevant (r-help is for general R programming questions, mostly) and more likely to have participants with suitable expertise. Cheers, Bert On Wed, Sep 11, 2013 at 12:32 PM, Maria Fernanda Bonetti < ferna

Re: [R] merge two lists by column

2013-09-10 Thread Bert Gunter
?do.call ## as in do.call(rbind, yourlist) Cheers, Bert On Tue, Sep 10, 2013 at 4:00 AM, Rosario Garcia Gil wrote: > Hello > > I have done resampling from a matrix data with two variables (A,B). After > resampling a get a set of lists (see below example for resample size 2). In > both lists

Re: [R] merge two lists by column

2013-09-10 Thread Rosario Garcia Gil
Hello I have done resampling from a matrix data with two variables (A,B). After resampling a get a set of lists (see below example for resample size 2). In both lists I have the same two variables (A,B). I want to export this data to an excel file where I have only two columns, one per variabl

Re: [R] merge matrix row data

2013-08-01 Thread arun
  D0407 D0409 D0410 D0462 D0463 D0473 D0475 D0488 D0489 D0492 #Conti_Australia 0 0 1 0 0 0 0 0 0 0 #Conti_Korea 0 0 0 0 0 0 0 0 0 0 #Conti_Malay 0 0 0 1 0 0     0     0     0 0  #   

Re: [R] merge matrix row data

2013-08-01 Thread arun
  0 1 0 0 0 0 #Conti_Malay 0 0 0 0 0 1 0 0 0 0 #Island_Sumatra  0 0 0 0 0     0     0     0 0 1 #    D0493 D0504 D0536 #Conti_Australia 0 0 1 #Conti_Malay 1 0 1 #Island_Sumatra 

Re: [R] merge matrix row data

2013-08-01 Thread arun
10 D0462 D0463 D0473 D0475 D0488 D0489 D0492 D0493 D0504 #IslandA 0 0 0 0 0 0 0 0 0 0 0 0 #IslandB     0     0 0 0 0 1 0 0 0 0 1 0  #   D0536 #IslandA 0 #IslandB 1 A.K. __

Re: [R] merge matrix row data

2013-08-01 Thread Elaine Kuo
t;> requested you to dput() the data to reduce these confusions. >> >> mat1<-as.matrix(read.table(text=" >> GID D0989 D9820 D5629 D4327 D2134 >> 1 100 1 0 >> 2 011 0 0 >> 4

Re: [R] merge matrix row data

2013-07-31 Thread arun
dA","IslandB"),function(x) {x1<- mat1[match(gsub(".*\\s+","",get(x)),mat1[,1]),-1];(!!colSums(x1))*1})) #    D0989 D9820 D5629 D4327 D2134 #IslandA 1 1 0 1 0 #IslandB 0 1 1 0 1 A.K. __

Re: [R] merge matrix row data

2013-07-31 Thread Elaine Kuo
10 0 0 > 7 010 0 1 > ",sep="",header=TRUE)) > IslandA<-c("GID 1", "GID 5") > IslandB<- c("GID 2", "GID 4", "GID > 7")t(sapply(c("IslandA","

Re: [R] merge matrix row data

2013-07-31 Thread Elaine Kuo
Sums(x1)})) > #D0989 D9820 D5629 D4327 D2134 > #IslandA FALSE FALSE TRUE FALSE TRUE > #IslandB TRUE FALSE FALSE TRUE FALSE > > t(sapply(c("IslandA","IslandB"),function(x) {x1<- > mat1[match(gsub(".*\\s+","",get(x)),row.names(m

  1   2   3   4   >