na

How do I specify different color ranges for different levels?

淺唱寂寞╮ 提交于 2019-12-03 06:22:11
I am making a lattice levelplot from x and y factors that range from [0,1]: x y level 1 m3134 m3134 1.0000000 2 m3134 m416B 0.4189057 3 m416B m3134 0.2696508 4 m3134 mA20 0.3322170 5 mA20 m3134 0.2454191 6 m3134 mB 0.3176792 ... Here is the R script that I use to make the figure from this data: #!/foo/bar/bin/Rscript --vanilla args <- commandArgs(TRUE) mtxFn <- args[1] pdfFn <- args[2] mtx <- read.table(mtxFn, col.names=c("x", "y", "level")) mtx$level[(mtx$level == 1)] <- NA library(lattice) trellis.device(dev=pdf, file=pdfFn) colors <- colorRampPalette(c('red', 'white'))(256) fig <- levelplot

visual structure of a data.frame: locations of NAs and much more

情到浓时终转凉″ 提交于 2019-12-03 03:27:23
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 data, to visualize it in a single glance. Perhaps someone have already developed a package to do it, but I couldn't find one (just this ). So here is a rough mockup of my "vision", kind of a heatmap, showing in color codes: the NA locations, the class of variables (factors (how many levels?), numeric (with color gradient, zeros, outliers...), strings) dimensions etc..... So far I have just written a

How to create an empty matrix in R?

99封情书 提交于 2019-12-03 01:48:49
问题 I am new to R. I want to fill in an empty matrix with the results of my for loop using cbind . My question is, how can I eliminate the NAs in the first column of my matrix. I include my code below: output<-matrix(,15,) ##generate an empty matrix with 15 rows, the first column already filled with NAs, is there any way to leave the first column empty? for(`enter code here`){ normF<-`enter code here` output<-cbind(output,normF) } The output is the matrix I expected. The only issue is that its

R gbm handling of missing values

回眸只為那壹抹淺笑 提交于 2019-12-03 01:25:24
Does anyone know how gbm in R handles missing values? I can't seem to find any explanation using google. To explain what gbm does with missing predictors, let's first visualize a single tree of a gbm object. Suppose you have a gbm object mygbm . Using pretty.gbm.tree(mygbm, i.tree=1) you can visualize the first tree on mygbm, e.g.: SplitVar SplitCodePred LeftNode RightNode MissingNode ErrorReduction Weight Prediction 0 46 1.629728e+01 1 5 9 26.462908 1585 -4.396393e-06 1 45 1.850000e+01 2 3 4 11.363868 939 -4.370936e-04 2 -1 2.602236e-04 -1 -1 -1 0.000000 271 2.602236e-04 3 -1 -7.199873e-04 -1

How to deal with NA in a panel data regression?

[亡魂溺海] 提交于 2019-12-03 00:21:44
I am trying to predict fitted values over data containing NA s, and based on a model generated by plm . Here's some sample code: require(plm) test.data <- data.frame(id=c(1,1,2,2,3), time=c(1,2,1,2,1), y=c(1,3,5,10,8), x=c(1, NA, 3,4,5)) model <- plm(y ~ x, data=test.data, index=c("id", "time"), model="pooling", na.action=na.exclude) yhat <- predict(model, test.data, na.action=na.pass) test.data$yhat <- yhat When I run the last line I get an error stating that the replacement has 4 rows while data has 5 rows. I have no idea how to get predict return a vector of length 5... If instead of

Efficient method to subset drop rows with NA values in R

最后都变了- 提交于 2019-12-02 21:10:26
Background Before running a stepwise model selection, I need to remove missing values for any of my model terms. With quite a few terms in my model, there are therefore quite a few vectors that I need to look in for NA values (and drop any rows that have NA values in any of those vectors). However, there are also vectors that contain NA values that I do not want to use as terms / criteria for dropping rows. Question How do I drop rows from a dataframe which contain NA values for any of a list of vectors? I'm currently using the clunky method of a long series of !is.na's > my.df[!is.na(my.df

What's the best way to replace missing values with NA when reading in a .csv?

痴心易碎 提交于 2019-12-02 18:25:14
I have a .csv dataset with many missing values, and I'd like R to recognize them all the same way (the "correct" way) when I read the table in. I've been using: import = read.csv("/Users/dataset.csv", header =T, na.strings=c("")) This script fills all the empty cells with something, but it's not consistant. When I look at the data with head(import) , some missing cells are filled with <NA> and some missing cells are filled with NA . I fear that R treats these two ways of identifying missing values differently when start analyzing the dataset, so I'd like to have the import uniformly read in

in R does NA == NA?

≯℡__Kan透↙ 提交于 2019-12-02 18:13:32
问题 identical(NA, NA) returns TRUE , but the following code filters NA out of the date frame: library(tidyverse) filter(starwars, birth_year == birth_year) If NA does equal NA the starwars filtered data frame above should include birth years of NA . Why doesn't it? 回答1: NA is identical to NA, but doesn't equal it. If you run NA==NA , the response will be NA, because the equal operator doesn't apply to NAs. From the identical documentation: A call to identical is the way to test exact equality in

How to remove only rows that have all NA in R? [duplicate]

旧巷老猫 提交于 2019-12-02 17:16:28
问题 This question already has answers here : Remove rows with all or some NAs (missing values) in data.frame (16 answers) Removing empty rows of a data file in R (5 answers) How to remove rows where columns satisfy certain condition in data frame (2 answers) Closed last year . I have a data frame where only some of the rows have all NA. How do I loop through and delete all these rows? I tried na.omit() but that doesn't work. In this example I need rows 3 and 5 removed x1 <- c("Bob", "Mary","",

How to create an empty matrix in R?

别等时光非礼了梦想. 提交于 2019-12-02 15:22:46
I am new to R. I want to fill in an empty matrix with the results of my for loop using cbind . My question is, how can I eliminate the NAs in the first column of my matrix. I include my code below: output<-matrix(,15,) ##generate an empty matrix with 15 rows, the first column already filled with NAs, is there any way to leave the first column empty? for(`enter code here`){ normF<-`enter code here` output<-cbind(output,normF) } The output is the matrix I expected. The only issue is that its first column is filled with NAs. How can I delete those NAs? The default for matrix is to have 1 column.