data.table

Insert Column Name into its Value using R

好久不见. 提交于 2021-02-08 08:52:05
问题 I need to insert Column Name, Department, into its value. i have code like here: Department <- c("Store1","Store2","Store3","Store4","Store5") Department2 <- c("IT1","IT2","IT3","IT4","IT5") x <- c(100,200,300,400,500) Result <- data.frame(Department,Department2,x) Result The expected result is like: Department <- c("Department_Store1","Departmentz_Store2","Department_Store3","Department_Store4","Department_Store5") Department2 <- c("Department2_IT1","Department2_IT2","Department2_IT3",

Creating new column based on multiple possible cell possibilities across several columns

人盡茶涼 提交于 2021-02-08 08:25:50
问题 data[, allkneePR := Reduce(`|`, lapply(.SD, `==`, "0082")), .SDcols=PR1:PR3] Hey, I'm trying to look for different diagnoses c("0082", "0083", "0084") across a range of rows and columns in data.table (the dataset is huge). If one of the values is "0082" or "0083" or "0084" in any of the columns PR1:PR3 I want another column that indicates true. Right now this works with the above code, but I am trying to add in multiple diagnoses, not just "0082". I tried the any() function which doesn't work

Creating new column based on multiple possible cell possibilities across several columns

不想你离开。 提交于 2021-02-08 08:25:35
问题 data[, allkneePR := Reduce(`|`, lapply(.SD, `==`, "0082")), .SDcols=PR1:PR3] Hey, I'm trying to look for different diagnoses c("0082", "0083", "0084") across a range of rows and columns in data.table (the dataset is huge). If one of the values is "0082" or "0083" or "0084" in any of the columns PR1:PR3 I want another column that indicates true. Right now this works with the above code, but I am trying to add in multiple diagnoses, not just "0082". I tried the any() function which doesn't work

How to divide a given time series dataset into 4 hour window in R

房东的猫 提交于 2021-02-08 08:21:01
问题 I have a time series dataframe like this for a given day. Datetime <- c("2015-09-29 00:00:13", "2015-09-29 00:45:00", "2015-09-29 02:53:20", "2015-09-29 03:22:18", "2015-09-29 05:42:10", "2015-09-29 05:55:50", "2015-09-29 06:14:10", "2015-09-29 07:42:16", "2015-09-29 08:31:15", "2015-09-29 09:13:10", "2015-09-29 11:45:14", "2015-09-29 11:56:00", "2015-09-29 13:44:00", "2015-09-29 14:41:20", "2015-09-29 15:33:10", "2015-09-29 15:24:00", "2015-09-29 17:24:12", "2015-09-29 17:28:16", "2015-09-29

How to divide a given time series dataset into 4 hour window in R

巧了我就是萌 提交于 2021-02-08 08:20:10
问题 I have a time series dataframe like this for a given day. Datetime <- c("2015-09-29 00:00:13", "2015-09-29 00:45:00", "2015-09-29 02:53:20", "2015-09-29 03:22:18", "2015-09-29 05:42:10", "2015-09-29 05:55:50", "2015-09-29 06:14:10", "2015-09-29 07:42:16", "2015-09-29 08:31:15", "2015-09-29 09:13:10", "2015-09-29 11:45:14", "2015-09-29 11:56:00", "2015-09-29 13:44:00", "2015-09-29 14:41:20", "2015-09-29 15:33:10", "2015-09-29 15:24:00", "2015-09-29 17:24:12", "2015-09-29 17:28:16", "2015-09-29

Outer operation by group in R

人走茶凉 提交于 2021-02-08 08:13:24
问题 My problem involves calculating differences in prices across products for each period. With the sample data below product = c('A','A','A','B','B','B','C','C','C') date = as.Date(c('2016-09-12','2016-09-19', '2016-09-26','2016-09-12','2016-09-19', '2016-09-26', '2016-09-12','2016-09-19', '2016-09-26')) price = as.numeric(c(17, 14.7, 15, 14.69, 14.64, 14.63, 13.15, 13.15, 13.15)) df <- data.frame(product, date, price) The challenge is in the grouping, without which a simple call to the outer

shiny-bound-input class lost in R Shiny with DT and data.table

孤者浪人 提交于 2021-02-08 06:39:44
问题 I am trying to build a shiny app that uses dynamically created inputs within a data.table with the help of the DT package. In the reproducible example below, the shiny-input input$Sel_Group_1 created within the DT-output depends on the value chosen in the shiny-input input$selectGroup (values a or b). The selected item (values c,d,f,g) are then shown in the textoutput output$selectedItem . When I initially launch the app everything works fine, but as soon as I update the value in input

How to use rbind to merge data tables with POSIXct and Date column classes?

怎甘沉沦 提交于 2021-02-08 05:10:37
问题 I would like to merge two data tables, but one of them has column ddate with POSIXct class and another one has column ddate with Date class. I would expect result data table to has POSIXct class, but the actual result depends on sequence of arguments passed to rbind : zz1 <- "or,d,ddate,rdate,changes,class,price,fdate,company,number,minutes,added,source VA1,VA2,2014-05-24,,0,0,2124,2014-05-22 15:50:16,,,,2014-05-22 12:20:03,ss VA1,VA2,2014-05-26,,0,0,2124,2014-05-22 15:03:44,,,,2014-05-22 12

read file with single line into R in fread or read.table

允我心安 提交于 2021-02-08 04:59:24
问题 I want to read a txt file into R this file has only file line, like this 1 NYC 2013-12-30 82 PM2.5 Ⅱ fair 2 London 2013-12-30 66 PM10.0 Ⅱ good there're no \n in this file, and all the what I want is a data.table incorporating these information like this: 1 NYC 2013-12-30 82 PM2.5 Ⅱ fair 2 London 2013-12-30 66 PM10.0 Ⅱ good Luckily, there're no NAs in the file, also I know for sure there're 7 fields for each observations. Could I achieve this using fread? or read.table? I tried this test <-

Memory leakage in using `ggplot` on large binned datasets

泪湿孤枕 提交于 2021-02-08 03:57:15
问题 I am making various ggplot s on a very large dataset (much larger than the examples). I created a binning function on both x- and y-axes to enable plotting of such large dataset. In the following example, the memory.size() is recorded at the start. Then the large dataset is simulated as dt . dt 's x2 is plotted against x1 with binning. Plotting is repeated with different subsets of dt . The size of the ploted object is checked by object.size() and stored. After the plotting objects have been