r

Create new variable by multiple conditions via mutate case_when

ε祈祈猫儿з 提交于 2021-02-15 06:14:09
问题 Hi want to create a new variable/column (WHRcat) by 2 variables (WHR and sexe) under a certain condition wth dyplr, mutate and case_when. Data: WHR sexe WHRcat (new variable) 1.5 1 2.8 2 0.2 2 0.3 1 1.1 1 My code: test<- test%>% mutate(WHRcat = case_when((WHR >= 1.02 & sexe = 1) ~ 1, (WHR < 1.02 & sexe = 1) ~ 2, (WHR >= 0.85 & sexe = 2) ~ 3, (WHR < 0.85 & sexe = 2) ~ 4, TRUE ~ 0)) Though doesnt work. Error: > test<- test%>% mutate(WHRcat = case_when((WHR >= 1.02 & sexe = 1) ~ 1, + (WHR < 1.02

Create new variable by multiple conditions via mutate case_when

£可爱£侵袭症+ 提交于 2021-02-15 06:12:48
问题 Hi want to create a new variable/column (WHRcat) by 2 variables (WHR and sexe) under a certain condition wth dyplr, mutate and case_when. Data: WHR sexe WHRcat (new variable) 1.5 1 2.8 2 0.2 2 0.3 1 1.1 1 My code: test<- test%>% mutate(WHRcat = case_when((WHR >= 1.02 & sexe = 1) ~ 1, (WHR < 1.02 & sexe = 1) ~ 2, (WHR >= 0.85 & sexe = 2) ~ 3, (WHR < 0.85 & sexe = 2) ~ 4, TRUE ~ 0)) Though doesnt work. Error: > test<- test%>% mutate(WHRcat = case_when((WHR >= 1.02 & sexe = 1) ~ 1, + (WHR < 1.02

Can't import binay h2o model with h2o.loadModel() function: 412 Precondition Failed

我是研究僧i 提交于 2021-02-15 04:59:08
问题 I've been working with h2o and h2o Flow for the past days and have loved it. Two days ago I exported some models (in binary format) from h2o Flow and imported them with R so I could do further studies. It worked perfectly until today. For some reason, I'm getting the following error when I try the h2o.loadModel function (which worked just fine before with all my exported binary models). Just to clarify, I already ran successfully the h2o.init() command to open the H2O cluster. ERROR:

ggplot2 order categorical stacked bars by proportions of y-axis

自古美人都是妖i 提交于 2021-02-15 04:53:05
问题 I have a data frame with categorical x-axis called Category and the yaxis is the Abundance, colored by Sequence. For each Category I am trying to reorder the stacks by the Abundance, so that it is easily visualized which sequence has the highest proportion at the bottom, to the lowest proportion at the top. Currently, I can make a bar graph like this: s<-"Sequence Abundance Category CAGTG 0.8 A CAGTG 0.2 B CAGTG 0.6 C CAGTG 0.3 D CAGTG 0.1 E GGGAC 0.1 A GGGAC 0.1 B GGGAC 0.3 C GGGAC 0.6 D

ggplot2 order categorical stacked bars by proportions of y-axis

给你一囗甜甜゛ 提交于 2021-02-15 04:51:37
问题 I have a data frame with categorical x-axis called Category and the yaxis is the Abundance, colored by Sequence. For each Category I am trying to reorder the stacks by the Abundance, so that it is easily visualized which sequence has the highest proportion at the bottom, to the lowest proportion at the top. Currently, I can make a bar graph like this: s<-"Sequence Abundance Category CAGTG 0.8 A CAGTG 0.2 B CAGTG 0.6 C CAGTG 0.3 D CAGTG 0.1 E GGGAC 0.1 A GGGAC 0.1 B GGGAC 0.3 C GGGAC 0.6 D

Transform NA values based on first registration and nearest values

南楼画角 提交于 2021-02-15 03:53:17
问题 I already made a similar question but now I want just to restrict the new values of NA. I have some data like this: Date 1 Date 2 Date 3 Date 4 Date 5 Date 6 A NA 0.1 0.2 NA 0.3 0.2 B 0.1 NA NA 0.3 0.2 0.1 C NA NA NA NA 0.3 NA D 0.1 0.2 0.3 NA 0.1 NA E NA NA 0.1 0.2 0.1 0.3 I would like to change the NA values of my data based on the first date a value is registered. So for example for A, the first registration is Date 2. Then I want that before that registration the values of NA in A are 0,

Transform NA values based on first registration and nearest values

左心房为你撑大大i 提交于 2021-02-15 03:52:17
问题 I already made a similar question but now I want just to restrict the new values of NA. I have some data like this: Date 1 Date 2 Date 3 Date 4 Date 5 Date 6 A NA 0.1 0.2 NA 0.3 0.2 B 0.1 NA NA 0.3 0.2 0.1 C NA NA NA NA 0.3 NA D 0.1 0.2 0.3 NA 0.1 NA E NA NA 0.1 0.2 0.1 0.3 I would like to change the NA values of my data based on the first date a value is registered. So for example for A, the first registration is Date 2. Then I want that before that registration the values of NA in A are 0,

applying same function on multiple files in R

谁都会走 提交于 2021-02-15 02:55:58
问题 I am new to R program and currently working on a set of financial data. Now I got around 10 csv files under my working directory and I want to analyze one of them and apply the same command to the rest of csv files. Here are all the names of these files: ("US%10y.csv", "UK%10y.csv", "GER%10y.csv","JAP%10y.csv", "CHI%10y.csv", "SWI%10y.csv","SOA%10y.csv", "BRA%10y.csv", "CAN%10y.csv", "AUS%10y.csv") For example, because the Date column in CSV files are Factor so I need to change them to Date

R ggplot2 Add today's date to the title

痞子三分冷 提交于 2021-02-13 17:34:21
问题 In principle, I'm sure this is straightforward.... How do I append today's date to my ggplot title? today.date <- Sys.Date() labs(title='Daily New COVID-19 Hospitalizations as of ', x=....) In other words, what's the R / ggplot syntax to append today.date to my plot title? Am I better off using ggtitle rather than labs for the title -- does that make it easier? Thank you! 回答1: Both with labs and ggtitle you can use function paste() as follows: labs(title = paste('Daily New COVID-19

in R: find all unique values in column separated by comma

北城以北 提交于 2021-02-13 17:27:04
问题 I have multiple observations of one species with different observers / groups of observers and want to create a list of all unique observers. My data look like this: data <- read.table(text="species observer 1 A,B 1 A,B 1 B,E 1 B,E 1 D,E,A,C,C 1 F" , header = TRUE, stringsAsFactors = FALSE) My output should return a list of all unique observers - so: A,B,C,E,F I tried to substring the data in column C using the following command but that only returns the unique combinations of observers. all