na Questions

1

Solved

Consider the following toy data and computations: library(dplyr) df <- tibble(x = 1) stats::sd(df$x) dplyr::summarise(df, sd_x = sd(x)) The first calculation results in NA whereas the seco...
Wolfsbane asked 14/12, 2017 at 13:2

2

To simplify, I have a data set which is as follows: b <- 1:6 # > b # [1] 1 2 3 4 5 6 jnk <- c(2, 4, 5, NA, 7, 9) # > jnk # [1] 2 4 5 NA 7 9 When I try: cor(b, jnk, na.rm=TRUE) I g...
rna
Belenbelesprit asked 14/7, 2015 at 16:38

4

I have a data.table with 57m records and 9 columns, one of which is causing a problem when I try to run some summary stats. The offending column is a factor with 3699 levels and I am receiveing an ...
Absentminded asked 4/12, 2013 at 20:8

4

Solved

I want to represent the structure of a data frame (or matrix, or data.table whatever) on a single plot with color-coding. I guess that could be very useful for many people handling various types of...
Lection asked 18/12, 2014 at 11:23

1

Solved

On a given double vector, how come I can define -999 to NA by v[v == -999] <- NA but not v[v == NaN] <- NA and how do I convert NaN's to NA's correctly?
Aer asked 28/7, 2017 at 15:24

1

Solved

I try to make a barplot with ggplot2 and am facing some issues with defining the color for NA. ggh <- ggplot(data=dat, aes(x=var1, fill=var2))+ geom_bar(position="dodge")+ scale_fill_manual( ...
Konstantin asked 17/7, 2017 at 12:42

4

Solved

I am trying to implement Chebyshev filter to smooth a time series but, unfortunately, there are NAs in the data series. For example, t <- seq(0, 1, len = 100) x <- c(sin(2*pi*t*2.3) + 0.2...
Politic asked 18/7, 2012 at 12:27

1

Solved

I am trying to replace NA values for a specific set of columns in my tibble. The columns all start with the same prefix so I am wanting to know if there is a concise way to make use of the starts_w...
Blazer asked 23/6, 2017 at 20:54

1

Solved

I am relatively new to R. I have a dataframe that has a column stored as a list. My column contain c("Benzo", "Ferri") or character(0) if it's empty. How can I change them to simply Benzo, Ferri an...
Jacquijacquie asked 20/6, 2017 at 17:30

3

Solved

As explained here when the test condition in ifelse(test, yes, no) is NA, the evaluation is also NA. Hence the following returns... df <- data.frame(a = c(1, 1, NA, NA, NA ,NA), b = c(NA, NA, ...
Lixiviate asked 7/6, 2017 at 10:56

2

Solved

I'm very new to R (moving over from SPSS). I'm using RStudio on a Mac running Mavericks. Please answer my question in words of 2 syllables as this is my first real attempt at anything like this. I'...
Elastin asked 13/8, 2014 at 23:13

2

Solved

Why would this operation fail? For example: a = pd.DataFrame({'a': [1,2,np.nan, np.nan], 'b': [5,np.nan,6, np.nan], 'c': [5, 1, 5, 2]}) a[['a', 'b']].fillna(0, inplace=True) and gave me this...
Indiraindirect asked 27/4, 2017 at 3:28

6

Solved

I'm looking for something similar to na.locf() in the zoo package, but instead of always using the previous non-NA value I'd like to use the nearest non-NA value. Some example data: dat <- c(1,...
Seigniorage asked 9/4, 2012 at 17:53

2

Solved

I am learning Pandas package by replicating the outing from some of the R vignettes. Now I am using the dplyr package from R as an example: http://cran.rstudio.com/web/packages/dplyr/vignettes/int...
Multifaceted asked 30/7, 2014 at 14:22

1

Solved

Consider the following example: require(tibble) require(dplyr) set.seed(42) tbl <- data_frame(id = letters[1:10], val = c(runif(5), NA, runif(4))) tbl # A tibble: 10 × 2 id val &lt...
Tiemroth asked 11/4, 2017 at 10:37

5

Solved

I would like to replace up to n consecutive NA values in vector with latest non-NA value. For example, if: a <- c(1,NA,NA,NA,NA,NA,2,NA,1,NA,NA,NA) n <- 2 I would like to obtain: c(1,1,1,NA,...
Eyla asked 4/4, 2017 at 12:58

2

Solved

I have a very messy dataframe (webscraped) that unfortunately has many double and even triple entries in it. Most of the dataframe looks like this: > df1<-data.frame(var1=c("a","a","b","b","...
Sophocles asked 29/3, 2017 at 17:45

3

Solved

I need to delete leading and trailing missing values (NA) from a vector. NAs between numbers should be kept. Note that my next step is index another vector without NA and keep only values with the ...
Hurdle asked 13/3, 2017 at 8:15

3

Solved

How could I Replace a NA with mean of its previous and next rows in a fast manner? name grade 1 A 56 2 B NA 3 C 70 4 D 96 such that B's grade would be 63.
Selway asked 7/4, 2014 at 15:18

2

Solved

I have got a map with a legend gradient and I would like to add a box for the NA values. My question is really similar to this one and this one. Also I have read this topic, but I can't find a "nic...
Scrawl asked 21/2, 2017 at 10:59

3

Solved

For example, I have this data frame (df): Color X1 X2 X3 X4 Red 1 1 0 2 Blue 0 NA 4 1 Red 3 4 3 1 Green 2 2 1 0 I would like to create a function that counts up the number of non-NAs in "X2&...
Trochee asked 25/1, 2017 at 13:52

2

Solved

I've just started with R and I've executed these statements: library(datasets) head(airquality) s <- split(airquality,airquality$Month) sapply(s, function(x) {colMeans(x[,c("Ozone", "Solar.R", ...
rna
Bicycle asked 11/1, 2017 at 10:26

3

Solved

I have a data.frame that has 100 variables. I want to get the sum of three variables only using mutate (not summarise). If there is NA in any of the 3 variables, I still want to get the sum. In or...
Shipmaster asked 8/1, 2017 at 6:7

3

Solved

I have a dataframe that has a scattering of NA's toy_df # Y X1 X2 Label # 5 3 3 A # 3 NA 2 B # 3 NA NA C # 2 NA 6 B I want to group this by the label field, and count how many non NA values are...
rna
Senn asked 14/12, 2016 at 19:2

1

Solved

I have a huge data set and want to predict (not replace) missing values with a machine learning algorithm like svm or random forest in python. My data set looks like this: ID i0 i1 i2 i3 i4 i5 ...
Contradict asked 6/12, 2016 at 13:1

© 2022 - 2024 — McMap. All rights reserved.