data.table

Unexpected error message while joining data.table with rbindlist() using mget()

╄→гoц情女王★ 提交于 2021-02-09 15:14:19
问题 While preparing this answer, I've got the error message Error: value for ‘spine_hlfs’ not found from running setDT(giraffe)[rbindlist(mget(df_names), idcol = "df.name"), on = "runkey", project := df.name][] while df_list <- mget(df_names) setDT(giraffe)[rbindlist(df_list, idcol = "df.name"), on = "runkey", project := df.name][] works as expected. Before reporting an issue on github, I want to verify with the community that this indeed is a bug or if there is a simple explanation for the error

Unable to subset (filter) a data frame due to NA's

China☆狼群 提交于 2021-02-08 19:12:12
问题 Why in the code below dplyr's filter doesn't return the same data.frame as base R subsetting? In fact none of them works as expected. I'd like to remove observations/rows which, simultaneously, b==1 AND c==1 . That is, I'd like to remove only the third row. require(dplyr) df <- data.frame(a=c(0,0,0,0,1,1,1), b=c(0,0,1,1,0,0,1), c=c(1,NA,1,NA,1,NA,NA)) filter(df, !(b==1 & c==1)) df[!(df$b==1 & df$c==1),] 回答1: Or use complete.cases to convert NA to FALSE in the result logic vector so that you

Unable to subset (filter) a data frame due to NA's

僤鯓⒐⒋嵵緔 提交于 2021-02-08 19:10:57
问题 Why in the code below dplyr's filter doesn't return the same data.frame as base R subsetting? In fact none of them works as expected. I'd like to remove observations/rows which, simultaneously, b==1 AND c==1 . That is, I'd like to remove only the third row. require(dplyr) df <- data.frame(a=c(0,0,0,0,1,1,1), b=c(0,0,1,1,0,0,1), c=c(1,NA,1,NA,1,NA,NA)) filter(df, !(b==1 & c==1)) df[!(df$b==1 & df$c==1),] 回答1: Or use complete.cases to convert NA to FALSE in the result logic vector so that you

Unable to subset (filter) a data frame due to NA's

淺唱寂寞╮ 提交于 2021-02-08 19:06:34
问题 Why in the code below dplyr's filter doesn't return the same data.frame as base R subsetting? In fact none of them works as expected. I'd like to remove observations/rows which, simultaneously, b==1 AND c==1 . That is, I'd like to remove only the third row. require(dplyr) df <- data.frame(a=c(0,0,0,0,1,1,1), b=c(0,0,1,1,0,0,1), c=c(1,NA,1,NA,1,NA,NA)) filter(df, !(b==1 & c==1)) df[!(df$b==1 & df$c==1),] 回答1: Or use complete.cases to convert NA to FALSE in the result logic vector so that you

Find immediate neighbors by group using data table or igraph

人走茶凉 提交于 2021-02-08 12:22:46
问题 I have a data.table : groups <- data.table(group = c("A", "B", "C", "D", "E", "F", "G"), code_1 = c(2,2,2,7,8,NA,5), code_2 = c(NA,3,NA,3,NA,NA,2), code_3 = c(4,1,1,4,4,1,8)) group code_1 code_2 code_3 A 2 NA 4 B 2 3 1 C 2 NA 1 D 7 3 4 E 8 NA 4 F NA NA 1 G 5 2 8 What I would like to achieve, is for each group to find the immediate neighbors based on the available codes. For example: Group A has immediate neighbors groups B, C due to code_1 (code_1 is equal to 2 in all groups) and has

Divide or split dataframe into multiple dfs based on empty row and header title

ⅰ亾dé卋堺 提交于 2021-02-08 12:09:36
问题 I have a dataframe which has multiple values in a single file. I want to divide it into multiple files around 25 from the file. Pattern for the file is where there is one blank row and a header title is there , it is a new df. I Have tried this Splitting dataframes in R based on empty rows but this does not take care of any blank row within the new df (V1 column 9th row). I want the data to be divided on empty row and a header title my data and code i have tried is given below . Also how can

Divide or split dataframe into multiple dfs based on empty row and header title

丶灬走出姿态 提交于 2021-02-08 12:09:29
问题 I have a dataframe which has multiple values in a single file. I want to divide it into multiple files around 25 from the file. Pattern for the file is where there is one blank row and a header title is there , it is a new df. I Have tried this Splitting dataframes in R based on empty rows but this does not take care of any blank row within the new df (V1 column 9th row). I want the data to be divided on empty row and a header title my data and code i have tried is given below . Also how can

converting multiple columns from wide to long using pivot_longer

我怕爱的太早我们不能终老 提交于 2021-02-08 11:47:19
问题 I get an error message when I want to convert multiple columns from wide to long with pivot_longer I have code which converts from wide to long with gather but I have to do this column by column. I want to use pivot_longer to gather multiple columns rather than column by column. This is some input data: structure(list(id = c("81", "83", "85", "88", "1", "2"), look_work = c("yes", "yes", "yes", "yes", "yes", "yes"), current_work = c("no", "yes", "no", "no", "no", "no"), before_work = c("no",

Subset by group with data.table compared to aggregate a data.table

北战南征 提交于 2021-02-08 09:29:27
问题 This is a follow up question to Subset by group with data.table using the same data.table: library(data.table) bdt <- as.data.table(baseball) # Aggregating and loosing information on other columns dt1 <- bdt[ , .(max_g = max(g)), by = id] # Aggregating and keeping information on other columns dt2 <- bdt[bdt[, .I[g == max(g)], by = id]$V1] Why do dt1 and dt2 differ in number of rows? Isn't dt2 supposed to have the same result just without loosing the respective information in the other columns

Insert Column Name into its Value using R

我是研究僧i 提交于 2021-02-08 08:52:38
问题 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",