na

Conditional row removal based on number of NA's within the row

烈酒焚心 提交于 2019-12-07 07:49:35
问题 I am looking to remove rows from my dataset based on two conditions as follows: Remove row if 3 consecutive cells are NA or If four or more cells are NA My sample data: data <- rbind(c(1,1,2,3,4,2,3,2), c(NA,1, NA, 4,1,1,NA,2), c(1,4,6,7,3,1,2,2), c(NA,3, NA, 1,NA,2,NA,NA), c(1,4, NA, NA,NA,4,3,2)) I have researched within the existing questions and found that na.omit or complete.cases can remove rows with NA but as I have conditions, doing further research I have found the following code

pandas dataframe replace blanks with NaN

Deadly 提交于 2019-12-07 00:52:00
问题 I have a dataframe with empty cells and would like to replace these empty cells with NaN. A solution previously proposed at this forum works, but only if the cell contains a space: df.replace(r'\s+',np.nan,regex=True) This code does not work when the cell is empty. Has anyone a suggestion for a panda code to replace empty cells. Wannes 回答1: I think the easiest thing here is to do the replace twice: In [117]: df = pd.DataFrame({'a':['',' ','asasd']}) df Out[117]: a 0 1 2 asasd In [118]: df

Using foreach loop in r returning NA

假装没事ソ 提交于 2019-12-06 16:55:41
I would like to use the "foreach" loop in R (package foreach + doParallel) but in my work i found that the loop returns some NA and the classic "for" loop returns the value I want : library(foreach) library(doParallel) ncore=as.numeric(Sys.getenv('NUMBER_OF_PROCESSORS'))-1 registerDoParallel(cores=ncore) B=2 a = vector() b = vector() foreach(i = 1:B, .packages = "ez",.multicombine = T,.inorder = T, .combine = 'c')%dopar%{ a[i] = i + 1 return(a) } for(i in 1:B){ b[i] = i + 1 b } As you can see if you try it, the object "a" returns a vector with 2, NA and 3 while the object "b" returns 2 and 3

R - Plotting a line with missing NA values

别等时光非礼了梦想. 提交于 2019-12-06 13:17:31
I have the following data.frame, "subset" Time A B C 2016-10-07 06:16:46 NA NA 41 2016-10-07 06:26:27 40 39 42 2016-10-07 06:38:23 NA 40 NA 2016-10-07 06:41:06 42 42 44 2016-10-07 06:41:06 NA 42 44 2016-10-07 06:41:06 NA 42 44 2016-10-07 06:41:07 44 43 48 2016-10-07 06:41:41 NA 43 48 2016-10-07 06:42:44 45 42 48 2016-10-07 06:48:40 46 45 48 I would like to have a plot where "Time" is the x-axis, "A" is a line and "B" and "C" are points. However, when i plot this, the only line that appears for "A" is the one connecting the last 2 dots (45 and 46), because these are the only 2 consecutive

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

﹥>﹥吖頭↗ 提交于 2019-12-06 11:57:45
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("vPWMETRO", "vPWPUMA00", "v100", "v101", "v102"), row.names = 26:30, class = "data.frame") m2<- structure(list

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

心不动则不痛 提交于 2019-12-06 06:49:11
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","Salary" ) table(census$Workclass) ? Federal-gov Local-gov Never-worked Private Self-emp-inc 1836 960

Interpolate multiple NA values with R

只谈情不闲聊 提交于 2019-12-06 05:25:03
问题 I want to interpolate multiple NA values in a matrix called, tester. This is a part of tester with only 1 column of NA values, in the whole 744x6 matrix other columns have multiple as well: ZONEID TIMESTAMP U10 V10 U100 V100 1 20121022 12:00 -1.324032e+00 -2.017107e+00 -3.278166e+00 -5.880225574 1 20121022 13:00 -1.295168e+00 NA -3.130429e+00 -6.414975148 1 20121022 14:00 -1.285004e+00 NA -3.068829e+00 -7.101699541 1 20121022 15:00 -9.605904e-01 NA -2.332645e+00 -7.478168285 1 20121022 16:00

Unlist a column while retaining character(0) as empty strings in R

匆匆过客 提交于 2019-12-06 05:14:51
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 and an empty string for character(0) instead? I'm not able to, for instance df$general_RN <- unlist(df$general_RN) because Error in $<-.data.frame(*tmp*, general_RN, value = c("Drug Combinations", : replacement has 1992 rows, data has 10479 I am assuming that all the character(0) have been removed but I need them retained as NA s. Here is what the column looks like general_RN c("Chlorambucil",

R: NA/NaN/Inf in foreign function call (arg 1)

别等时光非礼了梦想. 提交于 2019-12-06 03:50:43
When i use a package named HydroMe to fit a model, some data groups will return the following errors: Error in qr.default(.swts * attr(rhs, "gradient")) : NA/NaN/Inf in foreign function call (arg 1) Actually,there is no missing value in the data groups. the codes are as followed: library(HydroMe) fortst<-read.csv(file="F:/fortst.csv") van.lis <-nlsList(y~SSvan(x,Thr, Ths, alp, scal)|Sample,data=fortst) the example data canbe download from here: http://www.fileden.com/files/2012/9/13/3346981/fortst.csv The variables Thr , Ths , alp , and scal are not in your data frame or in fortst.csv . Thus,

Conditional row removal based on number of NA's within the row

拥有回忆 提交于 2019-12-05 18:03:45
I am looking to remove rows from my dataset based on two conditions as follows: Remove row if 3 consecutive cells are NA or If four or more cells are NA My sample data: data <- rbind(c(1,1,2,3,4,2,3,2), c(NA,1, NA, 4,1,1,NA,2), c(1,4,6,7,3,1,2,2), c(NA,3, NA, 1,NA,2,NA,NA), c(1,4, NA, NA,NA,4,3,2)) I have researched within the existing questions and found that na.omit or complete.cases can remove rows with NA but as I have conditions, doing further research I have found the following code within the existing questions: data[! rowSums(is.na(data)) >4 , ] data[! rowSums(is.na(data)) ==3 , ] The