data-manipulation

Shifting non-NA cells to the left

眉间皱痕 提交于 2019-12-17 05:13:53
问题 There are many NA's in my dataset and I need to shift all those cells (at row level) to the left. Example- my dataframe: df=data.frame(x=c("l","m",NA,NA,"p"),y=c(NA,"b","c",NA,NA),z=c("u",NA,"w","x","y")) df x y z 1 l <NA> u 2 m b <NA> 3 <NA> c w 4 <NA> <NA> x 5 p <NA> y I want the above dataframe converted into this: x y z 1 l u NA 2 m b NA 3 c w NA 4 x <NA> NA 5 p y NA Please help. Thanks. 回答1: You can use the standard apply function: df=data.frame(x=c("l","m",NA,NA,"p"),y=c(NA,"b","c",NA

Google Apps Script: Sheets Forms Data Manipulation, Deleting Rows if Certain Cells are Blank, while Maintaining Certain Columns

吃可爱长大的小学妹 提交于 2019-12-14 03:35:09
问题 This question is a continuation of the following: Google Apps Script: Sheets Forms Data Manipulation and Deleting Rows if Certain Cells are Blank I have a sheet "Form Responses" where users can fill out the same question up to 5 times. The following code will organize these lines row by row in the 'Paste Values' sheet. In addition to this, I have tried to sort the columns by the Timestamp column in ascending order (so that new replies from the google form will show up at the top). The first

Form groups of individuals python (pandas)

拈花ヽ惹草 提交于 2019-12-14 03:07:07
问题 I have a data set of the following form: import pandas as pd d1 = {'Subject': ['Subject1','Subject1','Subject1','Subject2','Subject2','Subject2','Subject3','Subject3','Subject3','Subject4','Subject4','Subject4'], 'Event':['1','2','3','1','2','3','1','2','3','1','2','3'], 'Category':['1','1','2','2','1','2','2','','2','1','1',''], 'Variable1':['1','2','3','4','5','6','7','8','9','10','11','12'], 'Variable2':['12','11','10','9','8','7','6','5','4','3','2','1'], 'Variable3': ['-6','-5','-4','-3'

“Transposing” some columns with ID fields into rows while copying the other data

我怕爱的太早我们不能终老 提交于 2019-12-13 21:44:42
问题 Suppose I inherited a table in Excel that dealt with processes and individuals, which (among thousands of other rows) looks similar to this. ID | Name | Quality1 | Quality2 | ... | QualityN | ... 234,014,828,423 James Low Hot . Blue 212,552,211 Mark Low Cold . Red 845 Amy High Hot . White ... I intend to use this data in Access later, as a reference table where each ID number is distinct and has data to go along with it. The first step is obviously to use the text to column tool in Excel to

Finding cooccurences between two variables within a group

和自甴很熟 提交于 2019-12-13 07:47:01
问题 I am hoping to efficiently compute a co-occurence matrix by finding the co-occurences between two different variables within a group, ideally without using a complex loop that iterates through all possible combinations. Given that my dataframe looks as follows: df = data.frame(group = c(1,1,1,2,2,2),var1 = c(1,2,4,2,2,4),var2 = c(4,1,2,1,3,2)) > df group var1 var2 1 1 1 4 2 1 2 1 3 1 4 2 4 2 2 1 5 2 2 3 6 2 4 2 I am hoping to turn this into a new co-occurence matrix, where the rows represent

How to decrease pitch of audio file in nodejs server side?

橙三吉。 提交于 2019-12-13 07:02:56
问题 I have a .MP3 file stored on my server, and I'd like to modify it to be a bit lower in pitch. I know this can be achieved by increasing the length of the audio, however, I don't know of any libraries in node that can do this. I've tried using the node web audio api, and soundbank-pitch-shift, but the former doesn't seem to have the capabilities of pitch shifting (AFAIK), and the latter seems designed toward client I need the solution within the realm of node ONLY- that means no external

How can I access and process nested objects, arrays or JSON?

╄→尐↘猪︶ㄣ 提交于 2019-12-13 06:58:42
问题 I have a nested data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or keys)? For example: var data = { code: 42, items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }] }; How could I access the name of the second item in items ? 回答1: Preliminaries JavaScript has only one data type which can contain multiple values: Object . An Array is a special form of object. (Plain) Objects have the form {key: value, key: value, ...}

Strange behaviour in fromJSON in RJSONIO package

雨燕双飞 提交于 2019-12-13 05:31:13
问题 Ok, I'm trying to convert the following JSON data into an R data frame. For some reason fromJSON in the RJSONIO package only reads up to about character 380 and then it stops converting the JSON properly. Here is the JSON:- "{\"metricDate\":\"2013-05-01\",\"pageCountTotal\":\"33682\",\"landCountTotal\":\"11838\",\"newLandCountTotal\":\"8023\",\"returnLandCountTotal\":\"3815\",\"spiderCountTotal\":\"84\",\"goalCountTotal\":\"177.000000\",\"callGoalCountTotal\":\"177.000000\",\"callCountTotal\"

Best way ho to validate ingested data

会有一股神秘感。 提交于 2019-12-13 05:19:19
问题 I am ingesting data daily from various external sources like GA, scrapers, Google BQ, etc. I store created CSV file into HDFS, create stage table from it and then append it to historical table in Hadoop. Can you share some best practices how to valide new data with historical one? Like for example compare row count of actual data with average of last 10 days or someting like that. Is there any prepared solution in spark or something? Thanks for advices. 来源: https://stackoverflow.com/questions

Read table by delimiter then by fixed width in R

99封情书 提交于 2019-12-13 04:38:36
问题 I have a tab-delimited file like this: RS1->2001 HAPLO1 AAACAAGGAGGAGAAGGAAA ... RS1->2001 HAPLO2 CAACAAAGAGGAGAAGGAAA ... RS1->2002 HAPLO1 AAAAAAGGAGGAAAAGGAAA ... RS1->20020 HAPLO2 CAACAAGGAGGAAGCAGAGC ... RS1->20021 HAPLO2 CAACAAGGAGGAAGCAGAGC ... In R we can easily read in these three columns, my problem is that I need separate the 3rd column character by character. The end result should be something like this: RS1->2001 HAPLO1 A A A C ... RS1->2001 HAPLO2 C A A C ... RS1->2002 HAPLO1 A A