missing-data

R Missing Value Replacement Function

一笑奈何 提交于 2019-12-08 06:58:38
问题 I have a table with missing values and I'm trying to write a function that will replace the missing values with a calculation based on the nearest two non-zero values. Example: X Tom 1 4.3 2 5.1 3 NA 4 NA 5 7.4 For X = 3 , Tom = 5.1 + (7.4-5.1)/2 . For X = 4 , Tom = (5.1 + (7.4-5.1)/2) + (7.4-5.1)/2 Does this function already exist? If not, any advice would be greatly appreciated. 回答1: A more usual way to do this (but not equivalent to the question) is to use linear interpolation: library(zoo

r - insert row for missing monthly data and interpolate

夙愿已清 提交于 2019-12-08 05:45:32
问题 I have a data frame as below with 5000+ rows. I am trying to insert a row where the month is missing e.g. month 6 below - and then utilise linear interpolation to calculate the 'TWS' value. Ideally the Decimal Date would be filled appropriately too but I can sort this afterwards if not! The data frame is months 1:12 for 10 years (2003-2012) but this repeats for multiple grid squares. I have found lots other similar questions but not relating to a repeating 1:12 monthly sequence. > head(ts

Correct for missing values in a Stacked area plot using ggplot2

僤鯓⒐⒋嵵緔 提交于 2019-12-08 04:39:02
问题 I've been trying to recreate this post on a combination of stacked bar/area plot. I have some problems with missing values though. Here's my data: https://www.dropbox.com/sh/pnkspwnn1qslm6u/JapTKCwqMS What I run is; wa=read.table('wa_class.txt', sep="", header=F, na.string="0") names(wa)=c("Class","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") wam=melt(wa) wam$variablen=as.numeric(wam$variable) How it looks like > head(wam) Class variable value variablen 1

Fill missing date-time values in output vector

不想你离开。 提交于 2019-12-08 04:34:07
问题 I performed a unique extraction on my date-time values for extracting unique seconds in my time-series data. unique_seconds <- unlist(unique(all_secondsDayData)) I have missing values in my output as follows: (see "2015-12-03 09:51:26") [1116] "2015-12-03 09:51:24" "2015-12-03 09:51:25" "2015-12-03 09:51:27" "2015-12-03 09:51:28" "2015-12-03 09:51:29" How do I fill my vector with these missing values? Do not worry about date because it is one day's data. The issue is filling the vector with

Fill up missing values using the other data?

一世执手 提交于 2019-12-07 23:56:09
问题 A <- data.frame(Item_A = c("00EF", "00EF", "00EF", "00EF", "00EF", "00FR", "00FR"), Item_B = c(NA, NA, NA, NA, "JAMES RIVER", NA, NA)) B <- data.frame(Item_A = c("00EF", "00EF", "00EF", "00FR", "00FR"), Item_B = c("JAMES RIVER", NA, "JAMES RIVER", "RICE MIDSTREAM", "RICE MIDSTREAM")) Expected: A <- data.frame(Item_A = c("00EF", "00EF", "00EF", "00EF", "00EF", "00FR", "00FR"), Item_B = c("JAMES RIVER", "JAMES RIVER", "JAMES RIVER", "JAMES RIVER", "JAMES RIVER", "RICE MIDSTREAM", "RICE

Find the missing values in Julia like R's is.na function

自古美人都是妖i 提交于 2019-12-07 18:26:11
问题 The Julia 1.0.0 documentation says this about missing values in Julia and R: In Julia, missing values are represented by the missing object rather than by NA. Use ismissing(x) instead of isna(x). The skipmissing function is generally used instead of na.rm=TRUE (though in some particular cases functions take a skipmissing argument). Here is example code in R that I would like to duplicate in Julia: > v = c(1, 2, NA, 4) > is.na(v) [1] FALSE FALSE TRUE FALSE (First note that is.na is the R

Substituting missing values in Python

亡梦爱人 提交于 2019-12-07 18:19:39
I want to substitute missing values (None) with the last previous known value. This is my code. But it doesn't work. Any suggestions for a better algorithm? t = [[1, 3, None, 5, None], [2, None, None, 3, 1], [4, None, 2, 1, None]] def treat_missing_values(table): for line in table: for value in line: if value == None: value = line[line.index(value)-1] return table print treat_missing_values(t) This is probably how I'd do it: >>> def treat_missing_values(table): ... for line in table: ... prev = None ... for i, value in enumerate(line): ... if value is None: ... line[i] = prev ... else: ...

Add missing values in time series efficiently

孤街醉人 提交于 2019-12-07 15:52:20
问题 I have 500 datasets (panel data). In each I have a time series (week) across different shops (store). Within each shop, I would need to add missing time series observations. A sample of my data would be: store week value 1 1 50 1 3 52 1 4 10 2 1 4 2 4 84 2 5 2 which I would like to look like: store week value 1 1 50 1 2 0 1 3 52 1 4 10 2 1 4 2 2 0 2 3 0 2 4 84 2 5 2 I currently use the following code (which works, but takes very very long on my data): stores<-unique(mydata$store) for (i in 1

count NA's appearing in between non-missing values

心不动则不痛 提交于 2019-12-07 15:36:06
问题 I have a data frame with 5 time columns (1st year, second y, etc), and for some rows I have NA's in between non-missing values. Sample below: df = structure(list(FirstYStage = c(NA, 3.2, 3.1, NA, NA, 2, 1, 3.2, 3.1, 1, 2, 5, 2, NA, NA, NA, NA, 2, 3.1, 1), SecondYStage = c(NA, 3.1, 3.1, NA, NA, 2, 1, 4, 3.1, 1, NA, 5, 3.1, 3.2, 2, 3.1, NA, 2, 3.1, 1), ThirdYStage = c(NA, NA, 3.1, NA, NA, 3.2, 1, 4, NA, 1, NA, NA, 3.2, NA, 2, 3.2, NA, NA, 2, 1), FourthYStage = c(NA, NA, 3.1, NA, NA, NA, 1, 4,

missing post data by using HttpWebRequest

痴心易碎 提交于 2019-12-07 11:45:16
问题 I got a problem on posting data by using HttpWebRequest. There is a string(ie. key1=value1&key2=value2&key3=value3 ) and I have post it to a site (ie. www.*.com/edit), but ,I don't know why that sometimes it's nothing wrong , but sometimes ,the first key=value1 will be missing, only key2=value&key3=value3 that can find in HttpAnalyzer . public static string SubmitData(string Url, string FormData, CookieContainer _Cc, string ContentType) { Stream RequestStream = null, ResponseStream = null;