data-manipulation

Use a character vector in the `by` argument

心不动则不痛 提交于 2020-07-03 03:24:21
问题 Within the data.table package in R, is there a way in order to use a character vector to be assigned within the by argument of the calculation? Here is an example of what would be the desired output from this using mtcars: mtcars <- data.table(mtcars) ColSelect <- 'cyl' # One Column Option mtcars[,.( AveMpg = mean(mpg)), by = .(ColSelect)] # Doesn't work # Desired Output cyl AveMpg 1: 6 19.74286 2: 4 26.66364 3: 8 15.10000 I know that this is possible to use assigning column names in j by

Use a character vector in the `by` argument

时光怂恿深爱的人放手 提交于 2020-07-03 03:24:09
问题 Within the data.table package in R, is there a way in order to use a character vector to be assigned within the by argument of the calculation? Here is an example of what would be the desired output from this using mtcars: mtcars <- data.table(mtcars) ColSelect <- 'cyl' # One Column Option mtcars[,.( AveMpg = mean(mpg)), by = .(ColSelect)] # Doesn't work # Desired Output cyl AveMpg 1: 6 19.74286 2: 4 26.66364 3: 8 15.10000 I know that this is possible to use assigning column names in j by

wide to long data table transformation with variables in columns and rows

元气小坏坏 提交于 2020-06-28 06:50:51
问题 I have a csv with multiple tables with variables stored in both rows and columns. About this csv: I'd want to go "wide" to "long" There are multiple "data frames" in one csv There are different types of variables for each "data frames" > df3 V1 V2 V3 V4 V5 V6 V7 V8 1 nyc 123 main st month 1 2 3 4 5 2 nyc 123 main st x 58568 567567 567909 35876 56943 3 nyc 123 main st y 5345 3673 3453 3467 788 4 nyc 123 main st z 53223 563894 564456 32409 56155 5 6 la 63 main st month 1 2 3 4 5 7 la 63 main st

Retrieving binary interactions from linkcomm package as a data frame in R

﹥>﹥吖頭↗ 提交于 2020-06-17 00:06:30
问题 Suppose I have the following clusters: library(linkcomm) g <- swiss[,3:4] lc <-getLinkCommunities(g) plot(lc, type = "members") getNodesIn(lc, clusterids = c(3, 7, 8)) From the plot you can see the node 6 is present in 3 overlapping clusters: 3, 7 and 8. I am interested to know how to retrieve the direct binary interactions in these clusters as a data frame. Specifically, I would like a data frame with the cluster id as the first column, and the last two columns as "interactor 1" and

Extracting certain rows from a CSV file in C++

陌路散爱 提交于 2020-05-12 10:57:07
问题 I would like to know how I can extract / skip certain rows where, for example, age == 32 or age == None from a CSV file in C++. Does it make more sense to extract the desired information after I loaded the entire csv file (if memory is not a problem)? EDIT : If possible, I would like to have a reading, printing and modification part. If possible, I want to use only the STL. The content of my test csv file looks as follows: *test.csv* name;age;weight;height;test Bla;32;1.2;4.3;True Foo;43;2.2

How to further melt a dataset?

[亡魂溺海] 提交于 2020-05-05 12:42:10
问题 I'm working with the following data: #Reproducible Example Bills <- c("93-HCONRES-106", "93-HCONRES-107", "93-HCONRES-108") Members <- c("00134", "00416;00010;00017;00026", "00416;00503;00513;00568") data <- data.frame(Bills, Members) Where the data looks like this: #Data Structure Bills Members 1 93-HCONRES-106 00134 2 93-HCONRES-107 00416;00010;00017;00026 3 93-HCONRES-108 00416;00503;00513;00568 What I would like is for the dataset to extend, such that each bill corresponds with each

How to remove columns and rows that sum to 0 while preserving non-numeric columns

送分小仙女□ 提交于 2020-04-10 04:59:05
问题 Below is a subset of my data. I am trying to remove columns AND rows that sum to 0 ... the catch is that I want to preserve columns 1 to 8 in the resulting output. Any ideas? I've tried quite a few. A tidy solution would be best. Site Date Mon Day Yr Szn SznYr A B C D E F G B0001 7/29/97 7 29 1997 Summer 1997-Summer 0 0 0 0 0 0 0 B0001 7/29/97 7 29 1997 Summer 1997-Summer 0 0 1 0 0 0 0 B0001 7/29/97 7 29 1997 Summer 1997-Summer 0 0 0 3 0 0 0 B0001 7/29/97 7 29 1997 Summer 1997-Summer 0 0 0 0