r

Time formatting: how to write a While loop that operates for a whole minute?

北城以北 提交于 2021-02-11 14:40:50
问题 I have written the following function: iterations_per_minute = function() { Sys.setenv(TZ='GMT+5') ## This line is optional; it just sets my timezone final_instant = as.numeric(format(Sys.time(), "%H.%M")) + 0.01 counter = 0 while(as.numeric(format(Sys.time(), "%H.%M")) < final_instant) { counter = counter + 1 } return(counter) } You can infer from the code what the function does, but allow me to explain in lay words anyway: what number can you reach by counting as fast as possible during one

Using values from slider in javascript DataTables calculations

隐身守侯 提交于 2021-02-11 14:39:45
问题 I've got a nested DataTable in my shiny app that is made from the data below. There are two sliders that I have which make up a percentage of 100. If one slider is 50 the other sider is 50. These two numbers from the two sliders help make up the Spot:30(%) and the Spot:15(%) columns of the child table. There is another column, Mix(%) , where the user is able to go in and edit the numbers. When the user edits this column the numbers in the Spot:30(%) and the Spot:15(%) columns are suppose to

How to replace \r\n characters in a text string specifically in R

房东的猫 提交于 2021-02-11 14:38:33
问题 For the life of me, I am unable to strip out some escape characters from a text string (prior to further processing). I've tried stringi, gsub, but I just cannot get the correct syntax. Here is my text string txt <- "c(\"\\r\\n Stuff from a webpage: That I scraped using webcrawler\\r\\n\", \"\\r\\n \", \"\\r\\n \", \"\\r\\n \", \"\\r\\n\\r\\n \", \"\\r\\n\\r\\n \", \"\\r\\n \\r\\n \", \"\\r\\n \")" I'd like to strip out "\\r\\n" from this string. I've tried gsub("[\\\r\\\n]", "", txt) (leaves

R: formatting axis and titles on plotly plots (time series)

青春壹個敷衍的年華 提交于 2021-02-11 14:37:55
问题 I am using the R programming language. Using the following tutorial : https://plotly.com/r/time-series/ and this stackoverflow question : How to plot multiple series/lines in a time series using plotly in R? I was able to make an interactive time series plot: library(xts) library(ggplot2) library(dplyr) library(plotly) library(lubridate) #time series 1 date_decision_made = seq(as.Date("2014/1/1"), as.Date("2016/1/1"),by="day") property_damages_in_dollars <- rnorm(731,100,10) final_data <-

R export to sas but cannot open

余生长醉 提交于 2021-02-11 14:35:55
问题 I export data from R to sas format with package haven . However, when I open my .sas7bdat data. It fails. library(haven) write_sas(M, "C:/Users/user/desktop/MERGED_data.sas7bdat") I provide my data structure below: Here is the properties. I double click the data to open in sas, but it fails and provides the information. Any suggestion? 来源: https://stackoverflow.com/questions/52031042/r-export-to-sas-but-cannot-open

I am having trouble with basic installing packages and library calling

雨燕双飞 提交于 2021-02-11 14:34:58
问题 When I execute install.packages("dplyr") I get Error: invalid version specification ‘NA’ In addition: Warning message: In utils:::packageDescription(packageName, fields = "Version") : no package 'knitr' was found Then I call the library and it obviously doesn't work either - library(dplyr) Error: package or namespace load failed for ‘dplyr’: .onLoad failed in loadNamespace() for 'pillar', details: call: utils::packageVersion("vctrs") error: package ‘vctrs’ not found In addition: Warning

Automisation of creating new variables based on the distribution of other variables in the data

佐手、 提交于 2021-02-11 14:34:05
问题 I have data as follows: EDIT: Sample of Original Data DT <- structure(list(Abbreviation = "AK", date = "1/31/2011", month = "01", year = "2011", c1 = "P", male = 12288, female = 6107, c4 = 2, upto22 = 870, from22to24 = 1441, from25to34 = 5320, from35to44 = 3568, from45to54 = 4322, from55to59 = 1539, from60to64 = 886, over65 = 451, c20 = 0, hispanic = 771, non_hispanic = 17458, c42 = 168, native = 4856, asian = 791, black = 611, hawaii = 289, white = 11209, c48 = 641), row.names = c(NA, -1L),

How do I get kable and formattable to work together when creating a table in R?

折月煮酒 提交于 2021-02-11 14:32:26
问题 Both kableExtra and formattable have fantastic features and I'll like to be able to incorporate them both in my tables. Here is the table formatted using formattable: Health_status = c("Very good", "Good", "Fair", "Bad", "Very bad", "Not stated", "Total") Number = c(1032169, 453975, 125502, 22095, 5019, 73528, 1712288) Percent = c(60.3, 26.5, 7.3, 1.3, 0.3, 4.3, 100) Change = c(37672, 15231, 6536, 1988, 525, 30315, 92267) Percent_Change = c(3.8, 3.5, 5.5, 9.9, 11.7, 70.2, 5.7) df <- data

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :

試著忘記壹切 提交于 2021-02-11 14:32:22
问题 When I knit my R Markdown document to pdf, some of my pages have this Error ## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : See screenshot below. What could be the problem? I am not using any new fonts and the laptop is a mac. 回答1: You are using an en-dash; for some reason there are specific bugs for this character. See R -e 'library(ggplot2); qplot(Sepal.Length, Petal.Length, data=iris, main="Big–booté")' open Rplots.pdf As you can see, the “é” characters are

How do I combine duplicate rows without losing unique data in R or VBA?

我只是一个虾纸丫 提交于 2021-02-11 14:32:18
问题 I have a table in excel where there's unique columns but many duplicate rows. Duplicates is measured by the column "uniqueID" which is an email stored as a string. Rows can have the same uniqueID but with missing data in other columns, or different data in the same column. I want to be able to combine and merge these duplicate rows such if the same uniqueID has the same response for the strings will be combined and concatenated such that data won't be lost. All data are strings. I've tried