similar to: Replace NAs in dataframe: what am I doing wrong

Displaying 20 results from an estimated 40000 matches similar to: "Replace NAs in dataframe: what am I doing wrong"

2007 Nov 24
2
'Split' character
Dear R-users, The following code splits a very simple dataframe into a list, each element of the list being one line of the dataframe. You will see that the split function names each element of the list by using uses the content of a and b and merging them with a "." character. Is there a way to customize this character? a<-1:10 b<-21:30 mydata<-data.frame(a,b)
2011 Jan 21
1
Reading gz compressed csv file - 'incomplete line found'
Hi all, I am trying to download, decompress and read a csv file. My code: myurl <- "ftp://ftp.ncbi.nih.gov/pub/geo/DATA/supplementary/series/GSE24729/GSE24729_MitoNuclear_suppl_male_stats.csv.gz" # myfile <- "GSE24729_MitoNuclear_suppl_male_stats.csv.gz" # download.file(myurl, destfile=myfile, mode="w") # mycon <- gzcon(gzfile(myfile,
2008 Aug 22
1
How to handle "~" character after csv importation
Dear R users, I have to import some csv files in which column headers contain the character "~". Following the following import call, the character seems to be replaced by dots in the column names of my data frame. Plus, I cannot query names(mydata) to find the column index which header should contain "~" or "." > mydata <-
2011 Jul 12
1
suggestions regarding reading in a messy file
I have a file in stata format, which I have read in, and I am trying to create a text file. I have exported the data using various delimiters, but I'm unable to read it back in. I originally read in the file with: library(foreign) myData <- read.dta("mydata.dta") I then exported it with write.table using comma, tab, and exclamation marks as a delimiter. When I was unable to
2007 Apr 26
4
select if + other questions
Hi, i am trying to read a .txt file, do a couple of select if statements on my data, and then finally use the ?table function to get frequency counts on the data. Specifically, i am looking at answering the following question: What is the frequency of Grade 7 students in the province of Alberta who are smokers? I am having some problems: 1)i cannot get the column names to show up when print
2011 Feb 13
2
creating NAs for some values only
Hello, I have some data file, say, mydata 1,2,3,4,5,6,7 3,3,4,4,w,w,1 w,3,6,5,7,8,9 4,4,w,5,3,3,0 i want to replace some percentages of "mydata" file in to NAs for those values that are NOT w's. I know how to apply the percentage thing here but don't know how to select those values that are not "w"s. So far, i was able to do it but the result replaces the w's
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 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)
2007 Nov 24
1
'Split' chracter
Dear R-users, The following code splits a very simple dataframe into a list, each element of the list being one line of the dataframe. You will see that the split function names each element of the list by using uses the content of a and b and merging them with a "." character. Is there a way to customize this character? a<-1:10 b<-21:30 mydata<-data.frame(a,b)
2007 Jun 11
2
Overlaying lattice graphs
Hello I apologize in advance if this question has already be posted on the list, although I could not find a relevant thread in the archives. I would like to overlay xyplots using different datasets for each plot. I typically work on the following data.frame (mydata) structure >mydata Drug Time Observed Predicted 1 A 0.05 10
2012 Jul 23
3
How to do the same thing for all levels of a column?
Dear all, I am a R beginner, and I am looking for a way to do the same thing for all levels of a column in a table. Basically, I have a bunch of protein sequences composed of different amino acid residues, and each residue is represented by an uppercase letter. I want to calculate the ratio of different amino acid residues at each position of the proteins. Here is an example table: Proteins
2007 Jun 21
2
Overlaying lattice graphs (continued)
Dear R Users, I recently posted an email on this list about the use of data.frame and overlaying multiple plots. Deepayan kindly indicated to me the panel.superposition command which worked perfectly in the context of the example I gave. I'd like to go a little bit further on this topic using a more complex dataset structure (actually the one I want to work on). >mydata Plot
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
2001 Aug 12
1
Creating a Model Matrix - keeping NAs
I am wanting to create a model matrix and keep the NAs. stratmat <- model.matrix(myformula,mydata) Is there any way to do this? model.matrix doesn't have na.action as a parameter. Elsewhere I have made use of na.keep <- function(x){x}. Many thanks, Rachel Cunliffe -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read
2007 Jun 24
2
matlab/gauss code in R
Hi all! I would like to import a matlab or gauss code to R. Could you help me? Bye, Sebasti?n. 2007/6/23, r-help-request en stat.math.ethz.ch <r-help-request en stat.math.ethz.ch>: > Send R-help mailing list submissions to > r-help en stat.math.ethz.ch > > To subscribe or unsubscribe via the World Wide Web, visit >
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
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 >
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
2007 Aug 06
3
Error in using nlevels in apply function
Dear R users, I am currently trying to create my first personnal function and use it with the apply function. The purpose of this function is to create a vector summarizing the number of levels in a given selection of data.frame columns. I tried to transpose the indexation method used by the nlevels function but it doesn't seem to work. I did not find anything uesful in the archives so
2007 Sep 06
1
change all . to 0 in a data.frame
Hello, I read in a tab delimited text file via mydata = read.delim(myfile). The text file was originally an excel file where . was used in place of 0. Now all the columns which should be integers are factors. Any ideas how to change all the . to 0 and factors back to integer? Thanks a lot in advance for any suggestions, -- D --------------------------------- [[alternative HTML