similar to: Replace selected columns of a dataframe with NA

Displaying 20 results from an estimated 20000 matches similar to: "Replace selected columns of a dataframe with NA"

2011 Jun 30
1
Match strings across two differently sized dataframes and copy corresponding row to dataframe
Hello- Sorry, this is a bit of a noob question, but I can't seem to progress it any further. I have two dataframes which contain a series of strings which exactly match. The problem is one has more rows than the other (more cases have been added) and they have been sorted so that they are not in the same order. The smaller dataframe, though, contains in another column which has codes
2011 May 27
1
Subset command and the : operator
Hello- I have some code that looks like this: with(mydatalocal, sum(table(Service[Time==5:8]))) This is designed to add up the numbers of responses between the Time codes 5 to 8 (which are integers and refer to quarters). Service is just one of the variables, I'm just trying to count the number of responses so I picked any of the variables. However, there is something wrong, it returns far
2012 Jan 09
3
as.numeric() generates NAs inside an apply call, but fine outside of it
Hello- I have rather a messy SPSS file which I have imported to R, I've dput'd some of the columns at the end of this message. I wish to get rid of all the labels and have numeric values using as.numeric. The funny thing is it works like this: as.numeric(mydata[,2]) # generates correct numbers however, if I pass the whole dataframe at once like this: apply(mydata, 1:2, function(x)
2011 Aug 29
3
Basic question about re-writing for loop as a function
Hello- Sorry to ask a basic question, but I've spent many hours on this now and seem to be missing something. I have a loop that looks like this: mainmat=data.frame(matrix(data=0, ncol=92, nrow=length(predata$Words_MH))) for(i in 1:length(predata$Words_MH)){ for(j in 1:92){ mainmat[i,j]=ifelse(j %in% as.numeric(unlist(strsplit(predata$Words_MH[i], split=","))),
2012 Dec 09
1
Some coefficients are doubled when I use the step() function
Hello- Such a strange problem, can't figure it out at all. Using binomial glm models, and the step() function, so the call looks like this: sectionmodel = glm(formula = Target3 ~ S1Q12_NUM.1 + S1Q9_NUM.1 + S1Q5_NUM.1 + S1Q7_NUM.1 + S1Q8_NUM.1 + S1Q6_NUM.1 + S1Q10_NUM.1 + S1Q12_BURG.1 + S1Q12_CD.1 + S1Q4.1 + S1Q12_OTHVIOL.1 + S1Q8.1 + S1Q12_GBH.1 + S1Q11.1 + S1Q7.1 + S1Q12_THEFT.1
2010 Aug 24
2
How to remove rows based on frequency of factor and then difference date scores
Hello- A basic question which has nonetheless floored me entirely. I have a dataset which looks like this: Type ID Date Value A 1 16/09/2020 8 A 1 23/09/2010 9 B 3 18/8/2010 7 B 1 13/5/2010 6 There are two Types, which correspond to different individuals in different conditions, and loads of ID labels (1:50)
2012 Mar 28
1
Nested brew call yields Error in .brew.cat(26, 28) : unused argument(s) (26, 28)
I am writing several webpages using the brew package and R2HTML. I would like to work off one script so I am using nested brew calls. The documentation for brew states that: "NOTE: brew calls can be nested and rely on placing a function named ?.brew.cat? in the environment in which it is passed. Each time brew is called, a check for the existence of this function is made. If it exists,
2005 Apr 13
1
How to plot Contour with NA in dataframe
Dear friends, I am trying to produce Contour Plot with R, but there are some NA in my data matrix. After I ran the following R script, I got the error message:"no proper `z' matrix specified". Does anybody know how to plot contour chart with R for the non-strict matrix? Thank you in advance!!!
2007 Aug 11
1
Replace NAs in dataframe: what am I doing wrong
Dear R-users, My script imports a dataset from a csv file, in which missing values are represented by ".". This importation is done into a dataframe using the read.table function with na.strings = "." Then I want to replace the NAs in the first column of the dataframe by "Missing data". I am using the following code to do so :
2007 Mar 15
2
replacing all NA's in a dataframe with zeros...
I've seen how to replace the NA's in a single column with a data frame *> mydata$ncigs[is.na(mydata$ncigs)]<-0 *But this is just one column... I have thousands of columns (!) that I need to do this, and I can't figure out a way, outside of the dreaded loop, do replace all NA's in an entire data frame (all vars) without naming each var separately. Yikes. I'm racking my
2009 Sep 03
2
dividing a dataframe column by different constants
Dear R users, today I've got the following problem. Here you are a dataframe as example. There are some SAMPLES for which a CONCentration was recorded through TIME. The time during which the concentration was recorded is not always the same, 10 points for Sample A, 7 points for Sample B and 11 for sample C Also the initial concentration was not the same for the three samples. I would like
2012 May 31
1
anova of lme objects (model1, model2) gives different results depending on order of models
Hello- I understand that it's convention, when comparing two models using the anova function anova(model1, model2), to put the more "complicated" (for want of a better word) model as the second model. However, I'm using lme in the nlme package and I've found that the order of the models actually gives opposite results. I'm not sure if this is supposed to be the case
2004 Sep 15
5
replacing NA's with 0 in a dataframe for specified columns
I know that there must be a cool way of doing this, but I can't think of it. Let's say I have an dataframe with NA's. > x <- data.frame(a = c(0,1,2,NA), b = c(0,NA,1,2), c = c(NA, 0, 1, 2)) > x a b c 1 0 0 NA 2 1 NA 0 3 2 1 1 4 NA 2 2 > I know it is easy to replace all the NA's with zeroes. > x[is.na(x)] <- 0 > x a b c 1 0 0 0 2 1 0 0 3 2 1
2011 Aug 12
1
odfWeave repeats output
Hello all- I'm having a problem with odfWeave. I'm still testing it out, and have used both of these code chunks, which I copied off a blog: Number 1: A sample document last processed \Sexpr{Sys.time()}. This simply illustrates the output from an R command inserted into our document. This is using \Sexpr{version$version.string}. Number 2: <<Sample1>>= summary(iris) @
2008 Jun 12
1
Data.matrix fail to convert data.frame into matrix
Hi, With the following codes, I attempt to convert the data.frame into a matrix. However I notice that data.matrix function doesn't seem to work. __ BEGIN__ dat <- read.table("mydata", comment.char = "!" , na.strings = "null"); # Select n-genes by random sample # n = 1 nosamp <- 1 geneid <- sequence(nrow(dat)) geneid.samp <- sample(geneid,nosamp)
2010 Apr 05
2
find the "next non-NA" value within each row of a data-frame
#I wish to find the "next non-NA" value within each row of a data-frame. #e.g. I have a data frame mydata. Rows 1, 2 & 3 have soem NA values. mydata <- data.frame(matrix(seq(20*6), 20, 6)) mydata[1,3:5] <-  NA mydata[2,2:3] <-  NA mydata[2,5] <-  NA mydata[3,6] <-  NA mydata[1:3,] #this loop accomplishes the task; I am tryign toi learn a "better" way for(i
2013 Jun 10
1
padding specific missing values with NA to allow cbind
Dear list Getting very frustrated with this simple-looking problem > m1 <- lm(x~y, data=mydata) > outliers <- abs(stdres(m1))>2 > plot(x~y, data=mydata) I would like to plot a simple x,y scatter plot with labels giving custom information displayed for the outliers only, i.e. I would like to define a column mydata$labels for the mydata dataframe so that the command >
2013 Feb 17
2
How to findout the name of a dataframe
Let'say we have a dataframe mydata with column v1. If mydata$v1 is passed to a function, is there way, then, to extract the name of the dataframe? What I now do is passing the name of the dataframe to the funcion, so passing two parameters. Maybe with mydata$v1 it is not possible, but with mydata['v1'] or mydata[,'v1'] it is? Thanks Frans ------------------- Frans Marcelissen
2010 Aug 04
3
split / lapply over multiple columns
Hi all, I have a data frame with column over which I would like to run repeated functions for data analysis. Currently I am only running recursively over two columns where I column 1 has two states over which I split and column two has 3 states. The function therefore runs 2 x 3 = 6 times as shown when running the following code: mydata <- data.frame(userid = c(5, 6, 5, 6, 5, 6), taskid =
2009 Aug 01
2
Add columns in a dataframe and fill them from another table according to a criteria
Deare R users I am new to R. What I want to do is explained below;- I have table called States.Prob which is given below:- This table gives the probabilities of the changes in the swap curve depending on the state of the swap curve. I want to put these probabilities in my dataframe mydata(given after the prob table). Prob of States Changes State1 State2 State3 State4 a