search for: date_time

Displaying 20 results from an estimated 35 matches for "date_time".

2017 Nov 09
4
weighted average grouped by variables
hi all I have this dataframe (created as a reproducible example) mydf<-structure(list(date_time = structure(c(1508238000, 1508238000, 1508238000, 1508238000, 1508238000, 1508238000, 1508238000), class = c("POSIXct", "POSIXt"), tzone = ""), direction = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"),...
2017 Nov 09
1
weighted average grouped by variables
Hello, Using base R only, the following seems to do what you want. with(mydf, ave(speed, date_time, type, FUN = weighted.mean, w = n_vehicles)) Hope this helps, Rui Barradas Em 09-11-2017 13:16, Massimo Bressan escreveu: > Hello > > an update about my question: I worked out the following solution (with the package "dplyr") > > library(dplyr) > > mydf%>% >...
2006 Jun 15
3
Can I call MySql statements directly??
Hi All. I have a mysql statement that I would really really like to call from my Ruby program which goes like this: SELECT a, b, DAYOFWEEK(date_time) as DOW, HOUR(date_time) at hr, AVG(x/y) FROM records; This is possible by creating a 3-dimentional array of a, b, date_time containing x/y, and then finding averages and putting it into a 4-dimensional array of a, b, dow, and hr. _3-dim_array_ a b date_time _4-dim_arra...
2017 Nov 09
0
weighted average grouped by variables
Hello an update about my question: I worked out the following solution (with the package "dplyr") library(dplyr) mydf%>% mutate(speed_vehicles=n_vehicles*mydf$speed) %>% group_by(date_time,type) %>% summarise( sum_n_times_speed=sum(speed_vehicles), n_vehicles=sum(n_vehicles), vel=sum(speed_vehicles)/sum(n_vehicles) ) In fact I was hoping to manage everything in a "one-go": i.e. without the need to create the "intermediate" variable called "speed_ve...
2006 Feb 08
1
Possible AGI Bug in Asterisk?
...= $dir.$finame; $finame = $finame.".gsm"; # populate the DB with the required information # Agent, Filename, date, time # Get the Date and Time $gdate = $dbh->selectrow_array ("SELECT current_date()"); $gtime = $dbh->selectrow_array ("SELECT current_time()"); $date_time = "$gdate $gtime"; # Cross reference the Agent Phone with extension $phone = $dbh1->selectrow_array ("SELECT phone from map where extn = '$extn'"); $agent = $dbh1->selectrow_array ("SELECT UserID from agent where phone = '$phone'"); # Put data i...
2009 Oct 06
1
ggplot2 applying a function based on facet
...library(gsubfn) DD <- strapply(L.DD, pat, c, simplify = rbind) DDdf <- data.frame(gauge = as.numeric(DD[,1]), gauge_name = DD[,2]) both <- merge(DF, DDdf, by = "gauge", all.x = TRUE) dts <- as.character(both[,"date"]) tms <- as.character(both[,"time"]) date_time <- as.chron(paste(dts, tms), "%Y-%m-%d %H:%M") DF <- data.frame(date_time, both) library(ggplot2) #discharge if(input=="discharge"){ qplot(as.POSIXct(date_time), discharge, data=DF, geom="line")+facet_wrap(~gauge_name, scales="free_y")+coord_trans(y=&qu...
2010 Oct 27
1
Fill in missing times in a timeseries with NA
...I have a irregularly spaced time series dataset, which reads in from a .csv. I need to convert this to a regularly spaced time series by filling in missing rows of data with NAs. So my data, called NtuMot, looks like this (I've removed some of the additional rows for simplicity).... ELEID date_time height slope 1 2009-06-24 00:00:00 150 4.0 1 2009-06-24 01:00:00 175 4.0 1 2009-06-24 02:00:00 180 2.3 1 2009-06-24 03:00:00 200...
2010 Mar 17
2
How can I return rows from a data frame with maximum value by factor?
Hi, I'm new to R and new to this forum. I'm struggling with trying to extract certain rows of data from my data.frame. The data.frame has eleven columns. Among those columns are "FISH_ID" and "DATE_TIME". FISH_ID is a factor. For each of my 21 unique FISH_IDs (levels) I have a few to a few thousand rows, each row with a unique DATE_TIME value. I would like to obtain, for each FISH_ID, the entire record from the data.frame with the latest DATE_TIME value (i.e. max (DATE_TIME). Thus, the result...
2017 Nov 09
1
weighted average grouped by variables
Dear Massimo, It seems straightforward to use weighted.mean() in a dplyr context library(dplyr) mydf %>% group_by(date_time, type) %>% summarise(vel = weighted.mean(speed, n_vehicles)) Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team...
2017 Nov 09
2
weighted average grouped by variables
...ct: Re: [R] weighted average grouped by variables > > Hello > > an update about my question: I worked out the following solution (with the > package "dplyr") > > library(dplyr) > > mydf%>% > mutate(speed_vehicles=n_vehicles*mydf$speed) %>% > group_by(date_time,type) %>% > summarise( > sum_n_times_speed=sum(speed_vehicles), > n_vehicles=sum(n_vehicles), > vel=sum(speed_vehicles)/sum(n_vehicles) > ) > > > In fact I was hoping to manage everything in a "one-go": i.e. without the need > to create the "intermediate...
2006 Jun 29
1
Newbie: Help Please - Model Validation Error
...tion'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/transactions.rb:126:in `save'' #{RAILS_ROOT}/app/controllers/admin_controller.rb:25:in `create'' Request Parameters: {"commit"=>"Create", "enquiry"=>{"date_time(1i)"=>"2006", "date_time(2i)"=>"6", "date_time(3i)"=>"30", "date_time(4i)"=>"00", "date_time(5i)"=>"13", "mytel"=>"1", "callback"=>"0", "m...
2017 Nov 11
0
weighted average grouped by variables
...les) sum(mydf$speed*mydf$n_vehicles)/sum(mydf$n_vehicles)) > gives you averages > The result of this calculation is: car light_duty heavy_duty motorcycle 36.54109 36.54109 36.54109 36.54109 But this doesn't give the same result as the dplyr method which is: date_time type vel <dttm> <fctr> <dbl> 1 2017-10-17 13:00:00 car 36.39029 2 2017-10-17 13:00:00 light_duty 38.56522 3 2017-10-17 13:00:00 heavy_duty 37.53333 4 2017-10-17 13:00:00 motorcycle 36.08696 The base R way of getting the result should be mod...
2011 May 18
3
Date_Time detected as Duplicated (but they are not!)
I have a problem with duplicated date_time stamps that I do not see as duplicated. I read a file with observations taken every 30 minutes: > aur2009=read.csv(paste(datadir,"AUR_ECPP_2009.csv",sep="/"),sep=";",stringsAsFactors=F) > aur2009[1:3,1:5] Date.Time E_filled E_filled_flag LE_filled LE_fill...
2010 May 18
2
Function that is giving me a headache- any help appreciated (automatic read )
...library(gsubfn) DD <- strapply(L.DD, pat, c, simplify = rbind) DDdf <- data.frame(gauge = as.numeric(DD[,1]), gauge_name = DD[,2]) both <- merge(DF, DDdf, by = "gauge", all.x = TRUE) dts <- as.character(both[,"date"]) tms <- as.character(both[,"time"]) date_time <- as.chron(paste(dts, tms), "%Y-%m-%d %H:%M") DF <- data.frame(Date=as.POSIXct(date_time), both) #change precip to numeric DF[,"precipitation"] <- as.numeric(as.character(DF[,"precipitation"])) precip.1 <- subset(DF, precipitation!="NA") b <-...
2008 Mar 17
0
arules - getting transaction data in
...help me with the "transactions" object. I am struggling to get my data in. I know the answer is in the help somewhere I'm sure, I just cannot find it. Essentially, I have data in this format (though I can change it if it particularly unsuitable) Transaction_id, store , salesman, date_time , items 1 , waterfront, john , 2008-01-01 12:00:00, hardware games audio_visual photo 2 , sandton , lisa , 2008-01-02 12:00:00, photo 3 , waterfront, peter , 2008-01-01 12:00:00, hardware photo How do I get this into a transactions data...
2009 Oct 06
2
ggplot cumsum refined question (?)
...a to two stations- one that has precipitation and one that does not. This is going to be in the context of a larger data set. I would like to be able to issue a ggplot command and have cum sum just act on the facets (factors) to apply this. library(chron) library(ggplot2) DF <- structure(list(date_time = structure(c(14522, 14522.0104166667, 14522.0208333333, 14522.03125, 14522.0416666667, 14522.0520833333, 14522.0625, 14522.0729166667, 14522.0833333333, 14522.09375, 14522.1041666667, 14522.1145833333, 14522.125, 14522.1354166667, 14522.1458333333, 14522.15625, 14522.1666666667, 14522.1770833333,...
2009 Apr 03
1
Convert factor to "double"?
Hi! I'm reading a tab-seperated CVS file with: test1 <- read.table("data.txt", header=TRUE) It's in the following format: Date_Time qK qL vL vP ... 0 30 22 110 88 ... ... (BTW: It seems to me R shifts the column descriptions by one.) Anyway, I would like to Fourier-transform one column. So I say: > fft(test1$vP) Error in levels(x)[x] : invalid subscript type 'complex' I guess this is some typing error but...
2005 Dec 15
6
passing parameters to link_to OR better way to do this?
...te presentation. The code below shows me trying a variation of something I found, but I''m unable to get any parameters through to the action.: rhtml ====== <% @logs.each do |log| %> <tr> <td><%= log.base_name %></td> <td><%= log.date_time %></td> <td><%= log.status %></td> <td><%= log.test_run_path %></td> <td><%= link_to log.test_results_path, :action => "show_results", :id => o, :params => { :result_file => log.test_results_path} %> </td&...
2006 Jul 19
4
sorting and pagination
...ds) [num,results,results2] end ############################## I added date_registered to the ferret fields and rebuilt the index (not sure if this is neccessary but anyway) but my results page still shows the results in a random order. Seems like the sorting has no effect. date_registered is a date_time field. I call ifnd by contents twice in the above code because i need to populate some dropdowns with values for the entire returned results so that they can be used to refine the search. Also just from the look of this code am i right in thinking that each page of results will be sorted but not t...
2006 Jul 31
0
MY worker won''t stop working
...phone_service_number = PhoneServiceNumber.find(:first, :conditions => "number = ''#{record[:charged_party]}''") customer_id = 0 customer_id = phone_service_number.customer_id if phone_service_number != nil phone_service_record.date_time = record[:date_time] phone_service_record.duration = record[:duration] phone_service_record.originating_number = record[:originating_number] phone_service_record.terminating_number = record[:terminating_number] phone_service_record.charged_party...