na

Combine rows and remove NA's

时光怂恿深爱的人放手 提交于 2019-12-13 03:37:29
问题 I have a data frame like this: idx type val1 val2 val3 val4 val5 val6 1 a 0.2 NA NA NA NA NA 2 a 0.3 NA NA NA NA NA 3 a 0.2 NA NA NA NA NA 4 a NA 0.3 NA NA NA NA 5 a NA 0.5 NA NA NA NA 6 a NA 0.2 NA NA NA NA 7 a NA NA 0.2 NA NA NA 8 a NA NA 0.5 NA NA NA 9 a NA NA 0.4 NA NA NA 10 a NA NA NA 0.4 NA NA 11 a NA NA NA 0.6 NA NA 12 a NA NA NA 0.6 NA NA . . . 34 b NA NA NA NA NA 0.6 35 b NA NA NA NA NA 0.4 36 b NA NA NA NA NA 0.3 I want to combine the rows and remove the NA's. So this is what I want

Replacing NA depending on distribution type of gender in R

笑着哭i 提交于 2019-12-13 03:04:46
问题 When i selected NA value here data[data=="na"] <- NA data[!complete.cases(data),] i must replace it, but depending on type of distribution. If using Shapiro.test the distribution by variables not normal, then missing value must be replace by median, If it's normal, than replace by mean. But distribution for each gender(1 girl, 2 -man) data=structure(list(sex = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), emotion = c(20L, 15L, 49L, NA, 34L, 35L, 54L, 45L), IQ = c(101L, 98L, 105L, NA, 123L, 120L, 115L,

How to substitute several NA with values within the DF using if-else in R?

怎甘沉沦 提交于 2019-12-13 02:38:53
问题 thank you for your time. I have the following data (snippet). Its from longitudinal data, reformed to a wide-format-file of work status, each colum represents one month, each row an individual. Code: j1992_12 = c(1, 10, 1, 7, 1, 1) j1993_01 = c( 1, 1, 1, NA, 3, 1) j1993_02 = c( 1, 1, 1, NA, 3, 1) j1993_03 = c( 1, 8, 1, NA, 3, 1) j1993_04 = c( 1, 8, 1, NA, 3, 1) j1993_05 = c( 1, 8, 1, NA, 3, 1) j1993_06 = c( 1, 8, 1, NA, 3, 1) j1993_07 = c( 1, 8, 1, NA, 3, 1) j1993_08 = c( 1, 8, 1, NA, 3, 1)

need to fill the NA values with the past three values before na values in python

让人想犯罪 __ 提交于 2019-12-13 02:14:22
问题 need to fill the NA values with the past three values mean of that NA this is my dataset RECEIPT_MONTH_YEAR NET_SALES 0 2014-01-01 818817.20 1 2014-02-01 362377.20 2 2014-03-01 374644.60 3 2014-04-01 NA 4 2014-05-01 NA 5 2014-06-01 NA 6 2014-07-01 NA 7 2014-08-01 46382.50 8 2014-09-01 55933.70 9 2014-10-01 292303.40 10 2014-10-01 382928.60 回答1: is this dataset a .csv file or a dataframe. This NA is a 'NaN' or a string ? import pandas as pd import numpy as np df=pd.read_csv('your dataset',sep=

summary still shows NAs after using both na.omit and complete.cases

◇◆丶佛笑我妖孽 提交于 2019-12-13 02:02:04
问题 I am a grad student using R and have been reading the other Stack Overflow answers regarding removing rows that contain NA from dataframes. I have tried both na.omit and complete.cases. When using both it shows that the rows with NA have been removed, but when I write summary(data.frame) it still includes the NAs. Are the rows with NA actually removed or am I doing this wrong? na.omit(Perios) summary(Perios) Perios[complete.cases(Perios),] summary(Perios) 回答1: The error is that you actually

Conditional Replacing with NA in R (two dataframes)

匆匆过客 提交于 2019-12-12 19:42:23
问题 I have idx <- c(1397, 2000, 3409, 3415, 4077, 4445, 5021, 5155) idy <- c( 1397, 2000, 2860, 3029, 3415, 3707, 4077, 4445, 5021, 5155, 5251, 5560) agex <- c(NA, NA, NA, 35, NA, 62, 35, 46) agey <- c( 3, 45, 0, 89, 7, 2, 13, 24, 58, 8, 3, 45) dat1 <- as.data.frame(cbind(idx, agex)) dat2 <- as.data.frame(cbind(idy, agey)) Now I want whenever agex = NA, and idx = idy, that agey = NA, so that idy agey 1 1397 NA 2 2000 NA 3 2860 0 4 3029 89 5 3415 7 6 3707 2 7 4077 NA 8 4445 24 9 5021 58 10 5155 8

Aggregating based on “near” row values

僤鯓⒐⒋嵵緔 提交于 2019-12-12 17:13:10
问题 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","c","c","d","d"),var2=c("right.a",NA,"right.b",NA,"right.c",NA,"right.d",NA),var3=c("correct.a","correct.a","correct.b","correct.b","correct.c","correct.c","correct.d","correct.d")) > df1 var1 var2 var3 1 a right.a correct.a 2 a <NA> correct.a 3 b right.b correct.b 4 b <NA> correct.b 5 c right.c correct.c 6

Make elements NA depending on a predicate function

不羁岁月 提交于 2019-12-12 15:14:36
问题 How can I easily change elements of a list or vectors to NAs depending on a predicate ? I need it to be done in a single call for smooth integration in dplyr::mutate calls etc... expected output: make_na(1:10,`>`,5) # [1] 1 2 3 4 5 NA NA NA NA NA my_list <- list(1,"a",NULL,character(0)) make_na(my_list, is.null) # [[1]] # [1] 1 # # [[2]] # [1] "a" # # [[3]] # [1] NA # # [[4]] # character(0) Note: I answered my question as I have one solution figured out but Id be happy to get alternate

Searching a vector/data table backwards in R

陌路散爱 提交于 2019-12-12 09:58:52
问题 Basically, I have a very large data frame/data table and I would like to search a column for the first, and closest, NA value which is less than my current index position. For example, let's say I have a data frame DF as follows: INDEX | KEY | ITEM ---------------------- 1 | 10 | AAA 2 | 12 | AAA 3 | NA | AAA 4 | 18 | AAA 5 | NA | AAA 6 | 24 | AAA 7 | 29 | AAA 8 | 31 | AAA 9 | 34 | AAA From this data frame we have an NA value at index 3 and at index 5. Now, let's say we start at index 8

The difference of na.rm and na.omit in R

。_饼干妹妹 提交于 2019-12-12 08:44:53
问题 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", "Wind")], na.rm = TRUE)}) lapply(s, function(x) {colMeans(na.omit(x[,c("Ozone", "Solar.R", "Wind")])) }) For the sapply , it returns the following: 5 6 7 8 9 Ozone 23.61538 29.44444 59.115385 59.961538 31.44828 Solar.R 181.29630 190.16667 216.483871 171.857143 167.43333 Wind 11.62258 10.26667 8.941935 8