na

marginal effects of mlogit in R

瘦欲@ 提交于 2019-11-29 08:41:44
I am new to R, and I don't understand yet completely the logic of its calculations... I cannot overcome my problem with the help from previous posts either. I have a data set of about 600 observations for 11 variables. I have successfully run the multinomial model on it, however I cannot achieve the marginal effects because my mean() command is getting NAs: The data set: > head(data,n=50) ID time CHINN DEBT ERA INFL MONEY OPENNESS RESERVES RGDP RSVS 1 POL 1993 -1.8639720 NA 0 32.8815343 33.47353 41.05223 4276726138 100.00000 4.2767261 2 POL 1994 -0.8081098 NA 0 30.7586977 31.98628 41.26984

How does R represent NA internally?

寵の児 提交于 2019-11-29 08:11:09
R seems to support an efficient NA value in floating point arrays. How does it represent it internally? My (perhaps flawed) understanding is that modern CPUs can carry out floating point calculations in hardware, including efficient handling of Inf, -Inf and NaN values. How does NA fit into this, and how is it implemented without compromising performance? R uses NaN values as defined for IEEE floats to represent NA_real_ , Inf and NA . We can use a simple C++ function to make this explicit: Rcpp::cppFunction('void print_hex(double x) { uint64_t y; static_assert(sizeof x == sizeof y, "Size does

Creating a function to replace NAs from one data.frame with values from another

℡╲_俬逩灬. 提交于 2019-11-29 06:16:30
问题 I regularly have situations where I need to replace missing values from a data.frame with values from some other data.frame that is at a different level of aggregation. So, for example, if I have a data.frame full of county data I might replace NA values with state values stored in another data.frame. After writing the same merge ... ifelse(is.na()) yada yada a few dozen times I decided to break down and write a function to do this. Here's what I cooked up, along with an example of how I use

R function prcomp fails with NA's values even though NA's are allowed

£可爱£侵袭症+ 提交于 2019-11-29 05:29:55
I am using the function prcomp to calculate the first two principal components. However, my data has some NA values and therefore the function throws an error. The na.action defined seems not to work even though it is mentioned in the help file ?prcomp Here is my example: d <- data.frame(V1 = sample(1:100, 10), V2 = sample(1:100, 10)) prcomp(d, center = TRUE, scale = TRUE, na.action = na.omit) d$V1[5] <- NA d$V2[7] <- NA prcomp(d, center = TRUE, scale = TRUE, na.action = na.omit) I am using the newest R version 2.15.1 for Mac OS X. Can anybody see the reason while prcomp fails? Here is my new

With the R package xlsx, is it possible to set na.strings when reading an Excel file?

空扰寡人 提交于 2019-11-29 04:52:19
I'm reading in an Excel file using read.xlsx , and I would like to set na.strings as you can with read.table . Is this possible? It doesn't work to just add na.strings to the call like this: Data <- read.xlsx("my file.xlsx", sheetName = "MyData", na.strings = "no info") Is there some other way to do it? No this is not possible for the simple reason that read.xlsx doesn't take care of special missing values. But this can be a possible enhancement for getCellvalue function. You can either replace missing values using something like : Data[Data=="no info"] <- NA Or, transform your data to a csv

How to replace empty string with NA in R dataframe?

烂漫一生 提交于 2019-11-29 02:34:26
My first approach was to use na.strings="" when I read the data in from a csv. This doesn't work for some reason. I also tried: df[df==''] <- NA Which gave me an error: Can't use matrix or array for column indexing. I tried just the column: df$col[df$col==''] <- NA This converts every value in the entire dataframe to NA, even though there are values besides empty strings. Then I tried to use mutate_all : replace.empty <- function(a) { a[a==""] <- NA } #dplyr pipe df %>% mutate_all(funs(replace.empty)) This also converts every value in the entire dataframe to NA. I suspect something is weird

Find columns with all missing values

点点圈 提交于 2019-11-28 22:56:44
I am writing a function, which needs a check on whether (and which!) column (variable) has all missing values ( NA , <NA> ). The following is fragment of the function: test1 <- data.frame (matrix(c(1,2,3,NA,2,3,NA,NA,2), 3,3)) test2 <- data.frame (matrix(c(1,2,3,NA,NA,NA,NA,NA,2), 3,3)) na.test <- function (data) { if (colSums(!is.na(data) == 0)){ stop ("The some variable in the dataset has all missing value, remove the column to proceed") } } na.test (test1) Warning message: In if (colSums(!is.na(data) == 0)) { : the condition has length > 1 and only the first element will be used Q1: Why is

STL decomposition of time series with missing values for anomaly detection

南楼画角 提交于 2019-11-28 21:25:10
问题 I am trying to detect anomalous values in a time series of climatic data with some missing observations. Searching the web I found many available approaches. Of those, stl decomposition seems appealing, in the sense of removing trend and seasonal components and studying the remainder. Reading STL: A Seasonal-Trend Decomposition Procedure Based on Loess, stl appears to be flexible in determining the settings for assigning variability, unaffected by outliers and possible to apply despite

Exclude Blank and NA in R [duplicate]

夙愿已清 提交于 2019-11-28 19:20:04
问题 Possible Duplicate: R - remove rows with NAs in data.frame I have a dataframe named sub.new with multiple columns in it. And I'm trying to exclude any cell containing NA or a blank space " ". I tried to use subset() , but it's targeting specific column conditional. Is there anyway to scan through the whole dataframe and create a subset that no cell is either NA or blank space ? In the example below, only the first line should be kept: # ID SNP ILMN_Strand Customer_Strand ID1234 [A/G] TOP BOT

Removing NA in dplyr pipe [duplicate]

蹲街弑〆低调 提交于 2019-11-28 16:17:58
This question already has an answer here: filter for complete cases in data.frame using dplyr (case-wise deletion) 6 answers I tried to remove NA's from the subset using dplyr piping. Is my answer an indication of a missed step. I'm trying to learn how to write functions using dplyr: > outcome.df%>% + group_by(Hospital,State)%>% + arrange(desc(HeartAttackDeath,na.rm=TRUE))%>% + head() Source: local data frame [6 x 5] Groups: Hospital, State Hospital State HeartAttackDeath 1 ABBEVILLE AREA MEDICAL CENTER SC NA 2 ABBEVILLE GENERAL HOSPITAL LA NA 3 ABBOTT NORTHWESTERN HOSPITAL MN 12.3 4 ABILENE