na

Add NA value to ggplot legend for continuous data map

陌路散爱 提交于 2019-12-09 15:34:49
问题 I'm using ggplot to map data values to a (fortified) SpatialPolygonsDataFrame, but many of the polygons have NA values because there is no data available. I used na.value = "white" to display the missing data correctly, but I'd like to add a box with a white fill in the legend (or a separate legend) with the label "no data". library(ggplot2) india.df <- read.csv('india.df.csv') # (I don't know how to provide this file to make the code reproducible) ggplot() + geom_polygon(data=india.df, aes(x

replace NA with 0 using starts_with()

给你一囗甜甜゛ 提交于 2019-12-08 18:27:14
问题 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_with() function from the dplyr package that would allow me to do this. I have seen several other questions on SO, however they all require the use of specific column names or locations. I'm really trying to be lazy and not wanting to define ALL columns, just the prefix. I've tried the replace_na()

Replace NA values in dataframe starting in varying columns

巧了我就是萌 提交于 2019-12-08 12:48:02
问题 This is a variation on the NA theme that I have not been able to find an answer to. I have monthly observations by column with a large number of series by row. Some missing values are genuine but some should be zero. I want to replace missing values for a given series with zeros but only after a value for that series has been observed. For example, given: Mth1 Mth2 Mth3 Mth4 1 1 2 1 3 2 NA 3 2 1 3 NA 2 1 NA 4 NA NA 2 NA 5 2 2 NA 2 I want to change this to: Mth1 Mth2 Mth3 Mth4 1 1 2 1 3 2 NA 3

Making a data frame of count of NA by variable for multiple data frames in a list

杀马特。学长 韩版系。学妹 提交于 2019-12-08 09:23:12
问题 I have a list containing 4 data frames: > names(listofdf) [1] "q12014local" "q12014national" "q22014local" "q22014national" All the data frames have the same variable names . I want to make a new data frame which counts the number of NAs by variable and by data frame. The resulting output should look like this: v1 v2 v3 v4 v5 v6 v7 q12014local 328 278 1786 0 0 12 1 q12014national 0 100 124 0 0 7 0 q22014local 0 0 0 0 0 289 0 q22014national 423 0 10 10 78 0 0 Here's a reproducible example: >

Merging data - Error in fix.by(by.x, x)

微笑、不失礼 提交于 2019-12-08 07:42:38
问题 I am trying to merge data in R as suggested in an answer to my other post here. Yet, I have an error. First let me explain what I try to do. I have 100 files (each have x_i and y_i), I want to merge them in this way: from: x1; y1 ; x2 ; y2 1 ; 100 ; 1 ; 150 4 ; 90 ; 2 ; 85 7 ; 85 ; 10 ; 60 10; 80 ; to x1; y1 ; x2 ; y2 1 ; 100 ; 1 ; 150 2 ; 100 ; 2 ; 85 4 ; 90 ; 4 ; 85 7 ; 85 ; 7 ; 85 10; 80 ;10 ; 60 The simple script works fine on the toy example: xx <- read.table(text='x1; y1 ; x2 ; y2 1 ;

“undefined columns selected” - when trying to remove na's from df's in list

左心房为你撑大大i 提交于 2019-12-07 20:58:52
问题 I am trying to replicate the success of this solution: remove columns with NAs from all dataframes in list or Remove columns from dataframe where some of values are NA with a list of dataframes: m1<- structure(list(vPWMETRO = c(1520L, 1520L, 1520L, 1520L, 1520L), vPWPUMA00 = c(500L, 900L, 1000L, 1100L, 1200L), v100 = c(96.1666666666667, 71.4615384615385, 68.6363636363636, 22.5, 64.5), v101 = c(5, 15, NA, NA, NA), v102 = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c(

R - 'NA' text treated as N/A

*爱你&永不变心* 提交于 2019-12-07 20:44:58
问题 I have a data frame in R including country iso codes. The iso code for Namibia happens to be 'NA'. R treats this text 'NA' as N/A. For example the code below gives me the row with Namibia. test <- subset(country.info,is.na(country.info$iso.code)) I initially thought it might be a factor issue, so I made sure the iso code column is character. But this didn't help. How can this be solved? 回答1: This probably relates to how you read in the data. Just because it's character doesn't mean your "NA"

R: Why does mean(NA, na.rm = TRUE) return NaN

我怕爱的太早我们不能终老 提交于 2019-12-07 20:09:54
问题 When estimating the mean with a vector of all NA's we get an NaN if na.rm = TRUE . Why is this, is this flawed logic or is there something I'm missing? Surely it would make more sense to use NA than NaN ? Quick example below mean(NA, na.rm = TRUE) #[1] NaN mean(rep(NA, 10), na.rm = TRUE) #[1] NaN 回答1: It is a bit pity that ?mean does not say anything about this. My comment only told you that applying mean on an empty "numeric" results in NaN without more reasoning. Rui Barradas's comment

how do I remove question mark(?) from a data set in R

爷,独闯天下 提交于 2019-12-07 18:35:30
问题 Hello everyone I am analysing UCI adult census data. The data has question marks ( ? ) for every missing value. I want to replace all the question marks with NA . i tried: library(XML) census<-read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data",header=F,na.strings="?") names(census)<-c("Age","Workclass","Fnlwght","Education","EducationNum","MaritalStatus","Occupation" ,"Relationship" , "Race","Gender","CapitalGain","CapitalLoss","HoursPerWeek","NativeCountry"

Cannot use `fill = NA` in cast

谁说胖子不能爱 提交于 2019-12-07 09:21:29
问题 I received the following error: dcast(rep.data, country ~ variable, mean, fill=NA) Error in vapply(indices, fun, .default) : values must be type 'logical', but FUN(X[[4]]) result is type 'double' Here is the rep.data data frame above: structure(list(id = c("MRT1996", "BFA1982", "LBR1990", "UKR2000", "MNG1993", "VEN1992", "OMN1987", "LAO1996", "OMN1982", "SYR1993" ), wbcode = c("MRT", "BFA", "LBR", "UKR", "MNG", "VEN", "OMN", "LAO", "OMN", "SYR"), polcode = c("MAA", "BFO", "LBR", "UKR", "MON",