Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread David L Carlson
4 5 4 3 6 4 3 4 5 ... $ Transit: Date, format: "1985-10-01" "1985-11-01" ... Would be preferable. --------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 From: Paul Bernal [mailto:paulberna...

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
-Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul > Bernal > Sent: Tuesday, March 28, 2017 9:12 AM > To: Ng Bo Lin > Cc: r-help@r-project.org > Subject: Re: [R] Looping Through DataFrames with Differing Lenghts > > Dear friends Ng Bo Li

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ng Bo Lin
Hi Paul, Using the example provided by Ulrik, where > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”, > "1986-01-01"), Transits = c(NA, NA, NA, NA)) > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = > c(15,20)), You could also try the following funct

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ng Bo Lin
Hi Paul, The date format that you have supplied to R isn’t exactly right. Instead of supplying the format “%Y-%m-%d”, it appears that the format of your data adheres to the “%e-%B-%y” format. In this case, %e refers to Day, and takes an integer between (0 - 31), %B refers to the 3 letter abbrev

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread David L Carlson
College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Bernal Sent: Tuesday, March 28, 2017 9:12 AM To: Ng Bo Lin Cc: r-help@r-project.org Subject: Re: [R] Looping Through DataFrames with Differing Lenghts Dear friends Ng Bo Lin, Mark and

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear Bo Lin, I tried doing Containerdata$TransitDate<-as.Date(Containerdata$TransitDate, "%e-%B-%y") but I keep getting NAs. I also tried a solution that I saw in stackoverflow doing: > lct<-Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C") [1] "C" > > Sys.setlocale("LC_TIME", lct) [1] "En

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and valuable replies, I am trying to reformat a date as follows: Data<-read.csv("Container.csv") DataFrame<-data.frame(Data) DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d") #trying to put it in -MM-DD for

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ulrik Stervbo
Hi Paul, does this do what you want? exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01", "1986-01-01"), Transits = c(NA, NA, NA, NA)) exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = c(15, 20)) tmpdf <- subset(exdf1, !Date %in% exdf2$Date) rbind(exdf2, tmp

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear friend Mark, Great suggestion! Thank you for replying. I have two dataframes, dataframe1 and dataframe2. dataframe1 has two columns, one with the dates in -MM-DD format and the other colum with number of transits (all of which were set to NA values). dataframe1 starts in 1985-10-01 (oct

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Anthoni, Peter (IMK)
Hi Paul, match might help, but without a real data sample, it is hard to check if the following might work. mm=match(df.col378[,"Date"],df.col362[,"Date"]) #mm will have NAs, where there is no matching date in df.col362 #and have the index of the match, where the two dates match new.df=cbind(df.

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Ulrik Stervbo
You could use merge() or %in%. Best, Ulrik Mark Sharp schrieb am Mo., 27. März 2017, 22:20: > Make some small dataframes of just a few rows that illustrate the problem > structure. Make a third that has the result you want. You will get an > answer very quickly. Without a self-contained reprodu

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Mark Sharp
Make some small dataframes of just a few rows that illustrate the problem structure. Make a third that has the result you want. You will get an answer very quickly. Without a self-contained reproducible problem, results vary. Mark R. Mark Sharp, Ph.D. msh...@txbiomed.org > On Mar 27, 2017,

[R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Paul Bernal
Dear friends, I have one dataframe which contains 378 observations, and another one, containing 362 observations. Both dataframes have two columns, one date column and another one with the number of transits. I wanted to come up with a code so that I could fill in the dates that are missing in o