na

Conditional NA filling by group

蓝咒 提交于 2020-01-12 14:32:23
问题 edit The question was originally asked for data.table . A solution with any package would be interesting. I am a little stuck with a particular variation of a more general problem. I have panel data that I am using with data.table and I would like to fill in some missing values using the group by functionality of data.table. Unfortunately they are not numeric, so I can't simply interpolate, but they should only be filled in based on a condition. Is it possible to perform a kind of conditional

Conditional NA filling by group

ε祈祈猫儿з 提交于 2020-01-12 14:30:09
问题 edit The question was originally asked for data.table . A solution with any package would be interesting. I am a little stuck with a particular variation of a more general problem. I have panel data that I am using with data.table and I would like to fill in some missing values using the group by functionality of data.table. Unfortunately they are not numeric, so I can't simply interpolate, but they should only be filled in based on a condition. Is it possible to perform a kind of conditional

Getting “NA” when I run a standard deviation

偶尔善良 提交于 2020-01-11 01:51:28
问题 Quick question. I read my csv file into the variable data . It has a column label var , which has numerical values. When I run the command sd(data$var) I get [1] NA instead of my standard deviation. Could you please help me figure out what I am doing wrong? 回答1: Try sd(data$var, na.rm=TRUE) and then any NAs in the column var will be ignored. Will also pay to check out your data to make sure the NA's should be NA's and there haven't been read in errors, commands like head(data) , tail(data) ,

Getting “NA” when I run a standard deviation

空扰寡人 提交于 2020-01-11 01:50:06
问题 Quick question. I read my csv file into the variable data . It has a column label var , which has numerical values. When I run the command sd(data$var) I get [1] NA instead of my standard deviation. Could you please help me figure out what I am doing wrong? 回答1: Try sd(data$var, na.rm=TRUE) and then any NAs in the column var will be ignored. Will also pay to check out your data to make sure the NA's should be NA's and there haven't been read in errors, commands like head(data) , tail(data) ,

How to na.locf in R without using additional packages [duplicate]

老子叫甜甜 提交于 2020-01-10 05:57:58
问题 This question already has answers here : propagating data within a vector (5 answers) Closed 6 years ago . Given a vector such as (say) c(2,NA,5,NA,NA,1,NA) the problem is to "last observation carry forward" resulting in vector c(2,2,5,5,5,1,1) . As answered here, na.locf from the zoo package can do this. However, given the simplicity of the problem, and the fact that this is to be performed many times from a "blank" R environment, I would like to do this without loading packages . Is there a

Fill missing values in the data.frame with the data from the same data frame

守給你的承諾、 提交于 2020-01-10 03:18:06
问题 I'm trying to backfill a fully outerjoined table with nearest preceding column data. The data frame I have looks like.. (No rows have both sides as NA and the table is sorted by date). date X Y 2012-07-05 00:01:19 0.0122 NA 2012-07-05 03:19:34 0.0121 NA 2012-07-05 03:19:56 0.0121 0.027 2012-07-05 03:20:31 0.0121 NA 2012-07-05 04:19:56 0.0121 0.028 2012-07-05 04:20:31 0.0121 NA 2012-07-05 04:20:50 0.0121 NA 2012-07-05 04:22:29 0.0121 0.027 2012-07-05 04:24:37 0.0121 NA 2012-07-05 20:48:45 0

How to subset data in R without losing NA rows?

随声附和 提交于 2020-01-08 21:56:01
问题 I have some data that I am looking at in R. One particular column, titled "Height", contains a few rows of NA. I am looking to subset my data-frame so that all Heights above a certain value are excluded from my analysis. df2 <- subset ( df1 , Height < 40 ) However whenever I do this, R automatically removes all rows that contain NA values for Height. I do not want this. I have tried including arguments for na.rm f1 <- function ( x , na.rm = FALSE ) { df2 <- subset ( x , Height < 40 ) } f1 (

How to subset data in R without losing NA rows?

一个人想着一个人 提交于 2020-01-08 21:55:51
问题 I have some data that I am looking at in R. One particular column, titled "Height", contains a few rows of NA. I am looking to subset my data-frame so that all Heights above a certain value are excluded from my analysis. df2 <- subset ( df1 , Height < 40 ) However whenever I do this, R automatically removes all rows that contain NA values for Height. I do not want this. I have tried including arguments for na.rm f1 <- function ( x , na.rm = FALSE ) { df2 <- subset ( x , Height < 40 ) } f1 (

Change maxgap for number of times a value is carried forward

笑着哭i 提交于 2020-01-06 02:38:36
问题 I have a data frame similar to the following: library(data.table) test <- data.table(data.frame("value" = c(5,NA,8,NA,NA,8,6,NA,NA,10), "locf_N" = c(1,NA,1,NA,NA,1,2,NA,NA,2)) ) In this data frame I have a variable that indicates the times I could carry forward the last observation (locf_N). This is not a fixed number for all observations. I have tried to use the maxgap parameter in the na.locf function for this purpose but it is not actually what I am looking for. require(zoo) test[,value :=

Handling NA's in aggregate function in R

痞子三分冷 提交于 2020-01-05 16:58:08
问题 I am trying to get the daily sum from a csv file using the aggregate function but I am encountering the following errors: Error in Summary.factor(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), na.rm = FALSE) : ‘sum’ not meaningful for factors Calls: aggregate ... aggregate.data.frame -> lapply -> FUN -> lapply -> Summary.factor Execution halted Here is the link to the data Data Here's my code: dat<-read.csv("Laoag_tc_induced.csv",header=TRUE,sep=",") dat[dat == -999] <- NA dat[dat == -888] <- 0 dat$Date