similar to: Changing NA to 0 in selected columns of a dataframe

Displaying 20 results from an estimated 10000 matches similar to: "Changing NA to 0 in selected columns of a dataframe"

2012 Aug 06
2
deleting columns from a dataframe where NA is more than 15 percent of the column length
I have a dataframe of 10 different columns (length of each column is the same). I want to eliminate any column that has 'NA' greater than 15% of the column length. Do i first need to make a function for calculating the percentage of NA for each column and then make another dataframe where i apply the function? Whats the best way to do this.
2012 Jun 07
3
conditional statement to replace values in dataframe with NA
Hello and thanks for helping. #some data L3 <- LETTERS[1:3] dat1 <- data.frame(cbind(x=1, y=rep(1:3,2), fac=sample(L3, 6, replace=TRUE))) #When x==1 and y==1 I want to replace the 1 values with NA #I can select the rows I want: dat2<-subset(dat1,x==1 & y==1) #replace the 1 with NA dat2$x<-rep(NA,nrow(dat2) dat2$y<-rep(NA,nrow(dat2) #select the other rows and rbind
2012 Aug 30
2
Identifying and Removing NA Columns and factor Columns with more than x Levels
Hi, How do you subset a dataframe so that you only have columns: 1. that contain one or more NAs? 2. that contain factors with greater than or equal to 32 levels? How do you remove from a dataframe columns** 3. with one or more NA's? 4. that contain factors with greater than or equal to 32 levels? ** I know how to remove columns at a basic level but I am trying
2012 Jul 14
2
Arrange two columns into a five variable dataframe
Hi, I hope that folks can give me some simple approaches to taking the data set below, which is accumulated in two columns called "long" and "group", then arrange the data is the "long" column into a data frame containing five variables: "Group 1", "Group 2", "Group 3", "Group 4", and "Group 5". I am hoping for a few
2017 Aug 04
1
Restructuring Star Wars data from rwars package
I'm having trouble restructuring data from the rwars package into a dataframe. Can someone help me? Here's what I have... library("rwars") library("tidyverse") # These data are json, so they load into R as a list people <- get_all_people(parse_result = T) people <- get_all_people(getElement(people, "next"), parse_result = T) # Look at Anakin
2012 Jul 01
2
list to dataframe conversion-testing for identical
HI R help, I was trying to get identical data frame from a list using two methods. #Suppose my list is: listdat1<-list(rnorm(10,20),rep(LETTERS[1:2],5),rep(1:5,2)) #Creating dataframe using cbind dat1<-data.frame(do.call("cbind",listdat1)) colnames(dat1)<-c("Var1","Var2","Var3") #Second dataframe conversion
2013 Apr 29
1
how to add new rows in a dataframe?
Hi, dat1<- read.table(text=" id??????????????? t???????????????????? scores 2???????????????? 0??????????????????????? 1.2 2???????????????? 2???????????????????????? 2.3 2???????????????? 3??????????????????????? 3.6 2???????????????? 4??????????????????????? 5.6 2???????????????? 6??????????????????????? 7.8 3???????????????? 0??????????????????????? 1.6 3????????????????
2008 May 11
1
Finding unmatched data between two dataframe using several factors
Hi R users I am trying to find unmatched data from two dataframes. I would like to find unmatched data based on several factors. For the following data: dat1 <- data.frame(x = paste("A", 1:6, sep=""), y = c("andy","bob","ciaran","dan", "eion", "fred")) dat1 dat2
2013 Jan 05
5
Need help on dataframe
Dear R users, I came up to a problem by taking means (or other summary statistics) of a big dataframe. Suppose we do have a dataframe: ID V1 V2 V3 V4 ........................ V71 1 6 5 3 2 ........................ 3 2 3 2 2 1 ........................ 1 3 6 5 3 2 ........................ 3 4 12 15 3 2 ........................ 100
2012 Jun 11
2
replacing values of matrix with random values of another dataframe
Hello, I'm having trouble performing a certain function within R and I was hoping someone might be able to help. I have a matrix (1000x21) that contains whole-number values ranging from 1-7 and I want to replace all entries within this matrix that have a value of 1 with a random number contained within a different dataframe that has 21 rows,1000 columns. I've tried using the if/else
2012 Nov 18
3
Replace <NA> with something else
I am reading some data into R from an Excel spreadsheet using read.csv. Some of the original data that comes into column 1 from the spreadsheet is text that says NA. The NA stands for north america. As it comes in, R converts the NA over to <NA>. What is the cleanest way to change the <NA> values to something else. In other words, get rid of the brackets ? Maybe convert <NA>
2013 Sep 02
1
R dataframe and looping help
HI, You may try this: dat1<- read.table(text=" CustID TripDate Store Bread Butter Milk Eggs 1 2-Jan-12 a 2 0 2 1 1 6-Jan-12 c 0 3 3 0 1 9-Jan-12 a 3 3 0 0 1 31-Mar-13 a 3 0 0 0 2 31-Aug-12 a 0 3 3 0 2 24-Sep-12 a 3 3 0 0 2 25-Sep-12 b 3 0 0 0 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat2<- dat1[,-c(1:3)] res<- lapply(seq_len(ncol(dat2)),function(i)
2012 Dec 17
4
Splitting up of a dataframe according to the type of variables
Dear R users, I have a dataframe which consists of variables of type numeric and factor. What is the easiest way to split up the dataframe to two dataframe which contain all variables of the type numeric resp. factors? Thank you very much for your efforts in advance! Best, Martin
2013 Apr 05
2
How to perform a grouped shapiro wilk test on dataframe
Hello, I was wandering if it is possible to perform on a dataframe called 'all' a shapiro wilk normality test for COUNTS by variable Group ACTIVITY? Could it be done using plyer? I saw an eg that applies to an array but not to a dataframe: lapply(split(dataset1$Height,dataset1$Group),shapiro.test) Any thoughts would be much appreciated. My dataframe is in shape: dat ACTIVIT
2012 Sep 15
4
how to view only readings of a selected data from a column while the other columns remain
Hi Friends I am new here and have a problem Year Market Winner BID 1 1990 ABC Apple 0.1260 2 1990 ABC Apple 0.1395 3 1990 EFG Pear 0.1350 4 1991 EFG Apple 0.1113 5 1991 EFG Orange 0.1094 For each year and separately for the two
2011 Jun 20
2
Replace selected columns of a dataframe with NA
I am using the following command to replace all the missing values and assorted typos in a dataframe with NA: mydata[mydata>80]=NA The problem is that the first column contains values which should be more than 80, so really I want to do it just for mydata[,2:length(mydata)] I can't seem to re-write the code to fit: mydata[,2:length(mydata)>80]=NA # no error message, but doesn't
2012 Oct 19
4
Creating a new by variable in a dataframe
Hello, I have a dataframe w/ 3 variables of interest: transaction,date(tdate) & time(event_tim). How could I create a 4th variable (last_trans) that would flag the last transaction of the day for each day? In SAS I use: proc sort data=all6; by tdate event_tim; run; /*Create last transaction flag per day*/ data all6; set all6; by tdate event_tim; last_trans=last.tdate; Thanks
2013 Nov 17
1
melt dataframe
Hi, Try: dat1 <- read.csv("precipitationRglimclim.csv",header=TRUE,stringsAsFactors=FALSE,sep="\t") library(reshape2) dat2M <- melt(dat1,id.var=c("year","month","day")) dat2M1 <- dat2M[with(dat2M,order(year,month,day,variable)),] ?dim(dat2M1) #[1] 1972320?????? 5 ?row.names(dat2M1) <- 1:nrow(dat2M1) ?colnames(dat2M1)[4:5] <-
2012 Jun 12
4
replacing NA for zero
Dear R users, I have a very basic query, but was unable to find a proper anwser. I have the following data.frame x y 2 0.12 3 0.25 4 0.11 6 0.16 7 0.20 and, due to further calculations, I need the data to be stored as x y 1 0 2 0.12 3 0.25 4 0.11 5 0 6 0.16 7 0.20 8 0 How do
2013 Mar 27
9
conditional Dataframe filling
Hi everyone: This may be trivial but I just have not been able to figure it out. Imagine the following dataframe: a b c d TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE I would like to create a new dataframe, in which TRUE gets 0 but if false then add 1 to the cell to the left. So the results for the example above should be something like: a b c