r

R POSIXct returns NA with “03/12/2017 02:17:13”

落爺英雄遲暮 提交于 2021-02-10 06:01:16
问题 I have a data set containing the following date, along with several others 03/12/2017 02:17:13 I want to put the whole data set into a data table, so I used read_csv and as.data.table to create DT which contained the date/time information in date. Next I used DT[, date := as.POSIXct(date, format = "%m/%d/%Y %H:%M:%S")] Everything looked fine except I had some NA values where the original data had dates. The following expression returns an NA as.POSIXct("03/12/2017 02:17:13", format = "%m/%d/

How to filter rows for every column independently using dplyr

丶灬走出姿态 提交于 2021-02-10 05:51:50
问题 I have the following tibble: library(tidyverse) df <- tibble::tribble( ~gene, ~colB, ~colC, "a", 1, 2, "b", 2, 3, "c", 3, 4, "d", 1, 1 ) df #> # A tibble: 4 x 3 #> gene colB colC #> <chr> <dbl> <dbl> #> 1 a 1 2 #> 2 b 2 3 #> 3 c 3 4 #> 4 d 1 1 What I want to do is to filter every columns after gene column for values greater or equal 2 (>=2). Resulting in this: gene, colB, colC a NA 2 b 2 3 c 3 4 How can I achieve that? The number of columns after genes actually is more than just 2. 回答1: One

How to filter rows for every column independently using dplyr

半腔热情 提交于 2021-02-10 05:50:06
问题 I have the following tibble: library(tidyverse) df <- tibble::tribble( ~gene, ~colB, ~colC, "a", 1, 2, "b", 2, 3, "c", 3, 4, "d", 1, 1 ) df #> # A tibble: 4 x 3 #> gene colB colC #> <chr> <dbl> <dbl> #> 1 a 1 2 #> 2 b 2 3 #> 3 c 3 4 #> 4 d 1 1 What I want to do is to filter every columns after gene column for values greater or equal 2 (>=2). Resulting in this: gene, colB, colC a NA 2 b 2 3 c 3 4 How can I achieve that? The number of columns after genes actually is more than just 2. 回答1: One

How to draw relative frequency table

▼魔方 西西 提交于 2021-02-10 05:49:10
问题 Src=as.factor(c("nc","us","us","nc","nc","ci","nn","pr","nc","nc","ak","ak","ak","ak","ci","hv","ak","ci","nc","nc")) Version = as.factor(c(0,4,7,0,0,0,9,0,0,0,1,1,1,1,0,2,1,0,0,0)) table(Src,Version) Output: Version Src 0 1 2 4 7 9 ak 0 5 0 0 0 0 ci 3 0 0 0 0 0 hv 0 0 1 0 0 0 nc 7 0 0 0 0 0 nn 0 0 0 0 0 1 pr 1 0 0 0 0 0 us 0 0 0 1 1 0 Instead of showing the counted numbers, can I instead show relative frequencies? 回答1: Sure. You can use prop.table() to that effect: prop.table(table(Src,

Julia FixedEffectsModels IV regression doesn't match R IV regression

怎甘沉沦 提交于 2021-02-10 05:48:18
问题 When I run (what I think is the same regression) in R and in Julia I get very different results. I think this is because the IV regression is using an indicator variable to instrument for another indicator variable but I can't figure out if I am doing something else wrong. I have tried several different methods, but the data starts like this: rc D tau May_ret Jun_ret Jul_ret Aug_ret Sep_ret 1 -43 0 0 0.04529617 0.02106667 0.009868421 0.032573290 0.010473186 2 -19 0 0 0.01973333 0.05752213 -0

sqldf: How to query based on a date condition

不羁的心 提交于 2021-02-10 05:44:45
问题 I have spent a couple of hours researching this but I am getting nowhere unfortunately. I am trying to get a subset of data by using sqldf to query a data frame, result. This is the structure of result: > str(result) 'data.frame': 316125 obs. of 6 variables: $ ID : int 1 2 3 4 5 6 7 8 9 10 ... $ dt : Date, format: "1999-12-31" "1999-12-31" "1999-12-31" "1999-12-31" ... $ Ticker: chr "0111145D US" "0113357D US" "0202445Q US" "0203524D US" ... $ px : num 32.5 20.6 34.2 21.4 11 ... $ High : num

how can I eliminate placeholder white space from shiny apps?

佐手、 提交于 2021-02-10 05:42:58
问题 When making shiny apps I often struggle with how to arrange plots and text outputs on the page for the user. So, I like to try an make it possible for a user to select which output to display. For instance, the user may be able to display 3 graphs and 2 chunks of text but may only want to display the first graph and one chunk of text. I can usually accomplish this using if statements inside of render functions. But, I have found shiny will still add white space even if...the user does not

Uploaded audio files does not play in r shiny

♀尐吖头ヾ 提交于 2021-02-10 05:41:25
问题 I have developed an app which takes an .wav file as input and plays it. However it seems to be not working. On the other hand, if the audio file is placed in /www folder and path name is given, it is playing fine. What am I doing wrong ? app.R library( shinydashboard ) ui = source( file.path( "ui", "ui.R" ), local = T )$value #..... ui for ocr server = function( input, output, session ){ #..... Include server logic for each tab ..... source( file.path( "server", "server.R" ), local = T )

Passing extra arguments to ggplot2 geoms: using ellipsis (…)

怎甘沉沦 提交于 2021-02-10 05:40:33
问题 This is a follow-up on this question. I am trying to write my own geoms with custom parameters. My question is how to use ellipsis (...) to pass extra arguments. The following example code works as expected: draw_panel_func <- function(data, panel_params, coord, showpoints=FALSE) { print(showpoints) if(showpoints) { coords <- coord$transform(data, panel_params) grid::pointsGrob(coords$x, coords$y) } else { zeroGrob() } } ## definition of the new geom. setup_data inserts the parameter ## into

forecast and fable return different outputs on same dataset for forecasting in R

情到浓时终转凉″ 提交于 2021-02-10 05:36:51
问题 I am trying to understand the different between two forecasting package forecast and fable , as the two editions of the same book (second edition and third edition seems to imply that the two packages are equivalent. library(dplyr) raw <- c(44.4082519001086, 47.1074380165289, 43.5633367662204, 43.1003584229391, 42.5828970331588, 38.3217993079585, 38.5751520417029) # raw <- c(raw,rev(raw)) forecast.df <- ts(raw) forecast::autoplot(forecast.df) + forecast::autolayer(forecast::holt(forecast.df