na

Array returning #N/A for some elements, want blank

 ̄綄美尐妖づ 提交于 2019-12-25 13:15:24
问题 I am using the excel tools OFFSET and INDEX to import an array from a different sheet, into a workbook with room for 7 entries. The sheet that is being referenced has an ID number and the number could be listed several times for different entries. If you are not familiar with the offset function, the second to last input is how many rows you want returned in the array. The number I have here is a COUNTIF for how many times an ID appears. My code works, however because it is in an array format

Indexing Julia's DataArrays with included NA values

好久不见. 提交于 2019-12-25 09:08:04
问题 I am wondering why indexing Julia's DataArrays with NA values is not possible. Excuting the snipped below results in an error(NAException("cannot index an array with a DataArray containing NA values")): dm = data([1 4 7; 2 5 8; 3 1 9]) dm[dm .== 5] = NA dm[dm .< 3] = 1 #Error dm[(!isna(dm)) & (dm .< 3)] = 1 #Working There is a solutions to ignore NA's in a DataFrame with isna() , like answered here. At a first glance it works like it should and ignoring NA's in DataFrames is the same approach

Replace NA row with non-NA value from previous row and certain column

一个人想着一个人 提交于 2019-12-25 06:32:45
问题 I have a matrix, where rows can have NA's for all columns. I want to replace these NA rows with previous row's non-NA value and K-th column. For example, this matrix: [,1] [,2] [1,] NA NA [2,] NA NA [3,] 1 2 [4,] 2 3 [5,] NA NA [6,] NA NA [7,] NA NA [8,] 6 7 [9,] 7 8 [10,] 8 9 Must be transformed to this non-NA matrix, where we use 2-th column for replacement: [,1] [,2] [1,] NA NA [2,] NA NA [3,] 1 2 [4,] 2 3 [5,] 3 3 [6,] 3 3 [7,] 3 3 [8,] 6 7 [9,] 7 8 [10,] 8 9 I wrote a function for this,

How to clean or remove NA values from a dataset without remove the column or row

亡梦爱人 提交于 2019-12-25 03:35:17
问题 Is any elegant solution to clean a dataframe from NA values without remove the row or column where the NA is? Example: Input dataframe C1 C2 C3 R1 A <NA> <NA> R2 <NA> A <NA> R3 <NA> <NA> A R4 B <NA> <NA> R5 <NA> B <NA> R6 <NA> <NA> <NA> R7 C <NA> B R8 C <NA> R9 <NA> R10 <NA> R11 C Output dataframe C1 C2 C3 R1 A A A R2 B B B R3 C C C For example, here is a messy dataframe (df1) full of NA values A B C D E F G H I J K 1 Healthy <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 2 <NA> Healthy

Removing NA values from a data frame or time-series object in R

余生长醉 提交于 2019-12-25 03:16:38
问题 I read in some data via: it.data <- read.csv("inputData/rstar.data.it.csv", header = T, sep = ",") then the second and fourth columns are inflation resp. interest: inflation.it <- it.data[2] and interest.it <- it.data[4] . However, the trouble starts when I am trying to reform the data into a time-series object, because there are leading and trailing NA values in the columns. I have tried na.omit() , it.data[complete.cases(it.data),] , na.contiguous , without luck. What happens now is that

R - tidyr - spread() - dealing with NA as column name

孤街醉人 提交于 2019-12-24 16:03:04
问题 I am spreading multiple categorical variables to Boolean columns using tidyr::spread() . As the data contains NAs, spread creates a new column without a name. What I'm looking for is a way to get rid off the NAs using a) a piping solution (I've tried select_() and '['() , but don't know how to refer to the NA column's name or index) or b) a custom function, which would be even better c) a way to simply not generate the NA columns, Hadleyverse compatible, if possible. Below is my current (and

Exporting lm summary output to dataframe including NA

穿精又带淫゛_ 提交于 2019-12-24 12:51:50
问题 I want to extract the coefficients (estimates, tvalues, etc) of LM ouputs to a dataframe. I need to store all coefficients in a dataframe for all regression outputs, since I have 949 separate outputs. The PROBLEM is that some of the outputs include NA's for a number of variables. When I export these summaries, it excludes the NA's and only outputs the variables that have true values. Since I need to bind all the values in rows, I want to maintain the same structure of all estimates (and so NA

Empty rows in list as NA values in data.frame in R

邮差的信 提交于 2019-12-24 11:33:54
问题 I have a dataframe as follows: hospital <- c("PROVIDENCE ALASKA MEDICAL CENTER", "ALASKA REGIONAL HOSPITAL", "FAIRBANKS MEMORIAL HOSPITAL", "CRESTWOOD MEDICAL CENTER", "BAPTIST MEDICAL CENTER EAST", "ARKANSAS HEART HOSPITAL", "MEDICAL CENTER NORTH LITTLE ROCK", "CRITTENDEN MEMORIAL HOSPITAL") state <- c("AK", "AK", "AK", "AL", "AL", "AR", "AR", "AR") rank <- c(1,2,3,1,2,1,2,3) df <- data.frame(hospital, state, rank) df hospital state rank 1 PROVIDENCE ALASKA MEDICAL CENTER AK 1 2 ALASKA

How to simplify a leading-NA count function, and generalize it to work on matrix, dataframe

空扰寡人 提交于 2019-12-24 11:28:39
问题 I wrote a leading-NA count function, it works on vectors. However: a) Can you simplify my version? b) Can you also generalize it to work directly on matrix, dataframe (must still work on individual vector), so I don't need apply() ? Try to avoid all *apply functions, fully vectorize, it must still work on a vector, and no special-casing if at all possible. leading_NA_count <- function(x) { max(cumsum((1:length(x)) == cumsum(is.na(x)))) } # v0.1: works but seems clunky, slow and unlikely to be

Remove rows which have all NA's, apart from the first column [duplicate]

六眼飞鱼酱① 提交于 2019-12-24 11:25:02
问题 This question already has an answer here : remove rows where all columns are NA except 2 columns [duplicate] (1 answer) Closed 6 months ago . I have a data.table which was formed by taking the differences between two panel observations using: tab <- tab[, lapply(.SD, function(x) x - shift(x)), by = A, .SDcols = (sapply(tab, is.numeric)) ] tab = data.table(A = c(1, 1, 2, 2), B = c(NA, 2, NA, 1), C = c(NA, NA, NA, 2), D=c(NA, 3, NA, 2) tab A B C D 1: 1 NA NA NA 2: 1 2 NA 3 3: 2 NA NA NA 4: 2 1