dataframe

Add new column to data.frame through loop in R

余生颓废 提交于 2021-02-11 12:40:58
问题 I have n number of data.frame i would like to add column to all data.frame a <- data.frame(1:4,5:8) b <- data.frame(1:4, 5:8) test=ls() for (j in test){ j = cbind(get(j),IssueType=j) } Problem that i'm running into is j = cbind(get(j),IssueType=j) because it assigns all the data to j instead of a , b . 回答1: As commented, it's mostly better to keep related data in a list structure. If you already have the data.frames in your global environment and you want to get them into a list, you can use:

How to calculate a formula that takes different columns of a dataframe with the same suffix in the name and create a new column?

走远了吗. 提交于 2021-02-11 12:40:52
问题 I have a dataframe in R that contains the following columns structure (in a bigger scale): Material_code actual_202009 actual_202010 actual_202011 pred_202009 pred_202010 pred_202011 111 30 44 24 25 52 27 112 19 70 93 23 68 100 I would like to add new columns to the dataframe containing the respective error measure: |actual - pred|/ actual * 100% Obtaining this: Material_code actual_202009 actual_202010 actual_202011 pred_202009 pred_202010 pred_202011 MAPE_202009 MAPE_202010 MAPE_202011 111

Add new column to data.frame through loop in R

血红的双手。 提交于 2021-02-11 12:39:17
问题 I have n number of data.frame i would like to add column to all data.frame a <- data.frame(1:4,5:8) b <- data.frame(1:4, 5:8) test=ls() for (j in test){ j = cbind(get(j),IssueType=j) } Problem that i'm running into is j = cbind(get(j),IssueType=j) because it assigns all the data to j instead of a , b . 回答1: As commented, it's mostly better to keep related data in a list structure. If you already have the data.frames in your global environment and you want to get them into a list, you can use:

Programmatically picking an inequality operator

怎甘沉沦 提交于 2021-02-11 12:23:23
问题 I'm trying to perform actions based on input from a config file. In the config, there will be specifications for a signal, a comparison, and a value. I'd like to translate that comparison string into a choice of inequality operator. Right now, this looks like def compute_mask(self, signal, comparator, value, df): if comparator == '<': mask = df[signal] < value elif comparator == '<=': mask = df[signal] <= value elif comparator == '=': mask = df[signal] == value elif comparator == '>=': mask =

Programmatically picking an inequality operator

我的未来我决定 提交于 2021-02-11 12:22:33
问题 I'm trying to perform actions based on input from a config file. In the config, there will be specifications for a signal, a comparison, and a value. I'd like to translate that comparison string into a choice of inequality operator. Right now, this looks like def compute_mask(self, signal, comparator, value, df): if comparator == '<': mask = df[signal] < value elif comparator == '<=': mask = df[signal] <= value elif comparator == '=': mask = df[signal] == value elif comparator == '>=': mask =

Add missing months for a range of date in R

左心房为你撑大大i 提交于 2021-02-11 12:01:22
问题 Say I have a data.frame as follows, each month has one entry of data: df <- read.table(text="date,gmsl 2009-01-17,58.4 2009-02-17,59.1 2009-04-16,60.9 2009-06-16,62.3 2009-09-16,64.6 2009-12-16,68.3",sep=",",header=TRUE) ## > df ## date gmsl ## 1 2009-01-17 58.4 ## 2 2009-02-17 59.1 ## 3 2009-04-16 60.9 ## 4 2009-06-16 62.3 ## 5 2009-09-16 64.6 ## 6 2009-12-16 68.3 Just wondering how could I fill missing month with gmsl as NaN for date range from 2009-01 to 2009-12 ? I have extracted year and

R: How to separate multiple choice, multiple answers questionnaire data that Google Forms put in one variable? [duplicate]

大城市里の小女人 提交于 2021-02-11 11:56:10
问题 This question already has answers here : Split a column of concatenated comma-delimited data and recode output as factors (2 answers) Closed 3 years ago . I have run a survey using Google Forms. I downloaded the response dataset as a spreadsheet, but unfortunately when it comes to multiple choice, multiple anwsers responses, the data looks something like this: Q1 Q2 Q3 1 "A, B ,C" S 2 "C, D" T 1 "A, C, E" U 3 "D" V 2 "B, E" Z I would like to have it in a form similar to the below: Q1 Q2 Q2A

How to add timestamp in R?

天大地大妈咪最大 提交于 2021-02-11 11:53:05
问题 I have a data which have the difference between the start and end time of an event. Now I want to add the difference. the problem is the difference time is in format difference_time _______________ 00:10:00 00:30:12 01:09:09 00:09:03 01:09:30 01:09:03 00:09:08 01:00:09 09:00:01 But if I do sum(df$difference_time) it throws the error that invalid type of arguement. I want the result to be something like below format: 51975 seconds. Any help is appreciated UPDATE: I tried period_to_seconds(hms

Removes text between two tags python

落爺英雄遲暮 提交于 2021-02-11 09:42:10
问题 I have dataframe. The df[0] contains Eukariota|Organisme eukariotik (hewan, tumbuhan, fungi, dan protista) menyimpan kebanyakan DNA-nya dalam inti sel dan sebagian kecil sisanya dalam organel seperti mitokondria ataupun kloroplas. < ref > {{cite book|last = Russell|first = Peter|title = iGenetics|publisher = Benjamin Cummings|location = New York|year = 2001|isbn = 0-8053-4553-1 }} < /ref > I want to remove: < ref > {{cite book|last = Russell|first = Peter|title = iGenetics|publisher =

Removes text between two tags python

丶灬走出姿态 提交于 2021-02-11 09:41:28
问题 I have dataframe. The df[0] contains Eukariota|Organisme eukariotik (hewan, tumbuhan, fungi, dan protista) menyimpan kebanyakan DNA-nya dalam inti sel dan sebagian kecil sisanya dalam organel seperti mitokondria ataupun kloroplas. < ref > {{cite book|last = Russell|first = Peter|title = iGenetics|publisher = Benjamin Cummings|location = New York|year = 2001|isbn = 0-8053-4553-1 }} < /ref > I want to remove: < ref > {{cite book|last = Russell|first = Peter|title = iGenetics|publisher =