na

Cumulative Returns with NA's in R

左心房为你撑大大i 提交于 2021-02-18 13:47:12
问题 I have the following data frame: df <- data.frame(Return1=c(NA, NA, .03, .04, .05), Return2=c(.25, .33, NA, .045, .90), Return3=c(.04, .073, .08, .04, .01)) Return1 Return2 Return3 1 NA 0.250 0.040 2 NA 0.330 0.073 3 0.03 NA 0.080 4 0.04 0.045 0.040 5 0.05 0.900 0.010 I would like to compute the cumulative returns, but there are missing values in the dataframe. I used: cumprod(df+1)-1 Getting as a result Return1 Return2 Return3 1 NA 0.2500 0.0400000 2 NA 0.6625 0.1159200 3 NA NA 0.2051936 4

Cumulative Returns with NA's in R

£可爱£侵袭症+ 提交于 2021-02-18 13:46:46
问题 I have the following data frame: df <- data.frame(Return1=c(NA, NA, .03, .04, .05), Return2=c(.25, .33, NA, .045, .90), Return3=c(.04, .073, .08, .04, .01)) Return1 Return2 Return3 1 NA 0.250 0.040 2 NA 0.330 0.073 3 0.03 NA 0.080 4 0.04 0.045 0.040 5 0.05 0.900 0.010 I would like to compute the cumulative returns, but there are missing values in the dataframe. I used: cumprod(df+1)-1 Getting as a result Return1 Return2 Return3 1 NA 0.2500 0.0400000 2 NA 0.6625 0.1159200 3 NA NA 0.2051936 4

R- Select rows with non-NA values in at least one of the four columns

无人久伴 提交于 2021-02-16 15:27:31
问题 I have this code that works fine: CompleteCoxObs<-temp[is.na(temp[,8])== FALSE | is.na(temp[,9])== FALSE | is.na(temp[,10])== FALSE,]; What is a better and more efficient way to achieve the same result? 回答1: You can try this to check for all the columns: CompleteCox.df <- temp.df[rowSums(is.na(temp.df)) != ncol(temp.df),] In your case: CompleteCox.df <- temp.df[rowSums(is.na(temp.df[, c(8,9,10)])) != 3,] 回答2: You can try one of the followings: temp[!is.na(rowSums(temp[,8:10])),] or temp[

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,

LSTM produces identical forecast for each input

不羁的心 提交于 2021-02-11 13:25:36
问题 I've been working on reproducing a CNN-LSTM model for PV power forecasting from literature for the past four weeks for my Master Thesis in Energy Science (http://www.mdpi.com/2076-3417/8/8/1286). However I've been stuck on a seemingly simple issue: Any configuration of LSTM model that I've tried yields one of two things: Rediculous output, makes no sense whatsoever (flat line, complete stochasticity, negative values, you name it) Exactly the same (very believable) PV power forecast. I've done

Plot conditional color with NA data

蹲街弑〆低调 提交于 2021-02-11 12:21:59
问题 I have a data frame in R that has 2 numeric fields, 1 of these fields can contain NA values. I want to plot the first field and base the col off if the second field is NA or not. CurrentBackLog = as.data.frame(list(DaysSinceCreted=c(34,50,22,6),DaysSinceReady=c(NA,10,22,NA))) This only shows the items where DaysSinceReady is NOT NA... plot(CurrentBackLog$DaysSinceCreated, main = 'Days Since Created by Ticket', ylab = 'Days Since Created', pch = 15, col = ifelse(CurrentBackLog$DaysSinceReady>1

Inserting NA in blank values from web scraping

无人久伴 提交于 2021-02-10 20:11:25
问题 I am working on scraping some data into a data frame, and am getting some empty fields, where I would instead prefer to have NA. I have tried na.strings, but am either placing it in the wrong place or it just isn't working, and I tried to gsub anything that was whitespace from beginning of line to end, but that didn't work. htmlpage <- read_html("http://www.gourmetsleuth.com/features/wine-cheese-pairing-guide") sugPairings <- html_nodes(htmlpage, ".meta-wrapper") suggestions <- html_text

Inserting NA in blank values from web scraping

怎甘沉沦 提交于 2021-02-10 20:10:36
问题 I am working on scraping some data into a data frame, and am getting some empty fields, where I would instead prefer to have NA. I have tried na.strings, but am either placing it in the wrong place or it just isn't working, and I tried to gsub anything that was whitespace from beginning of line to end, but that didn't work. htmlpage <- read_html("http://www.gourmetsleuth.com/features/wine-cheese-pairing-guide") sugPairings <- html_nodes(htmlpage, ".meta-wrapper") suggestions <- html_text

Ignoring NA values in function

拟墨画扇 提交于 2021-02-10 14:23:07
问题 Im writing my own function to calculate the mean of a column in a data set and then applying it using apply() but it only returns the first columns mean. Below is my code mymean <- function(cleaned_us){ column_total = sum(cleaned_us) column_length = length(cleaned_us) return (column_total/column_length) } Average_2 <- apply(numeric_clean_usnews,2,mymean,na.rm=T) 回答1: We need to use the na.rm=TRUE in the sum and using it in apply is not going to work as mymean doesn't have that argument mymean