similar to: How to replace all <NA> values in a data.frame with another ( not 0) value

Displaying 20 results from an estimated 1000 matches similar to: "How to replace all <NA> values in a data.frame with another ( not 0) value"

2010 May 04
2
R for web browser
Hi Everyone, Does anyone know of any projects for running an interactive R session within a web browser? I'm looking for something similar to the one on the Ruby website (http://tryruby.org), except for R. Thanks for your responses in advance! Lanna ----- Lanna Jin lannajin at gmail.com 510-898-8525 -- View this message in context:
2010 Mar 10
2
function to create multiple matrices
Hi All, If given a dataframe (long form) with Year, Species, and Location, How would I write a function that would create a unique matrix of Species & Location for each Year? What I've tried doing is the following: data #dataframe dataT<-table(data$Species,data$Location,data$Year) #creates tables of Species vs Location for each Year But I'm encountering issues individually
2010 May 03
8
Delete rows with duplicate field...
as a r noob i am having another problem: i have a big dataframe where each row corresponds to one entry and each column is a field... for instance, i have the column ID and time and many more... Id like to get a dataframe where all IDs are just included once (some users with that ID might have several entries but Id like to kepp only one).. when i use unique I only get a list of the levels (or
2012 May 20
5
removeing only rows/columns with "na" value from square ( symmetrical ) matrix.
I have some square matrices with na values in corresponding rows and columns. M<-matrix(1:2,10,10) M[6,1:2]<-NA M[10,9]<-NA M<-as.matrix(as.dist(M)) print (M) 1 2 3 4 5 6 7 8 9 10 1 0 2 1 2 1 NA 1 2 1 2 2 2 0 1 2 1 NA 1 2 1 2 3 1 1 0 2 1 2 1 2 1 2 4 2 2 2 0 1 2 1 2 1 2 5 1 1 1 1 0 2 1 2 1 2 6 NA NA 2 2 2 0 1 2 1 2 7 1 1 1 1 1 1 0 2 1 2 8
2012 Apr 10
7
How to remove $ (Dollar sign) from string
How do I remove a "$" character from a string sub() and gsub() with "$" or "\$" as pattern do not work. > sub("$","","ABC$DEF") [1] "ABC$DEF" > sub("\$","","ABC$DEF") Error: '\$' is an unrecognized escape in character string starting "\$" >
2009 Nov 06
1
using xyplot to plot frequencies
Hi all, First off, thank you for the overwhelming response last time. I'm still trying to figure out the syntax of R to plot some distributions of some frequencies. I've managed to plot histograms from the data, but I would like to clean it up using xyplot from library(lattice). Unfortunately I cannot find a solution to my problem. Given a dataframe "all2", with numerical
2012 Jan 21
2
replacing "+" in string
I am trying to replace "+" in a string with another character I am getting odd results using sub and gsub > X<-"one + two" > gsub("+","plus",X) [1] "plusoplusnpluseplus plus+plus plustpluswplusoplus" > sub("+","plus",X) [1] "plusone + two" > X<-"one ~ two" it seems to work fine with other
2011 Oct 16
2
How to plot CI's (llim ulim) on ecodist mgram
I would like to put confidence intervals on a mantel corellogram they are already calculated in the pmgram object but I am unsure how I get the x value in order to plot them? package(ecodist) X<-1:100 Y<-rnorm(1:100) Z<-rnorm(1:100) XY<-dist(data.frame(X,Y)) YX<-dist(data.frame(Y,X)) my.mgram<-mgram(XY,XZ) plot(my.mgram) print(my.mgram) > print(my.mgram) $mgram
2013 Aug 27
1
return the name of source.
Is there a fuction that will allow me to retrun the filename for a script from within that script. fir instance If I have a script "myscript.r": FileName<-unknown.fucntion() print(FileName) and run it source("myscript.r") will return "myscript.r" Thanks Nevil Amos [[alternative HTML version deleted]]
2010 Mar 16
1
nested looping functions and dataframes
Hey All, So, I am confused how exactly to use nesting loop functions in R to spit out data frames. I've managed to create a working function for my data set that generates a data frame for a given set of Year i and Location j; but how would I do it for all Years and Locations? Here is my working function: test<-function(i,j){ a<-x[which(x$Year==i & x$Location==j),]
2012 Jan 11
2
Vegan(ordistep) error: Error in if (aod[1, 5] <= Pin) { : missing value where TRUE/FALSE needed
I am getting the following erro rmessage in ordistep. I have a number of similarly structured datasets using ordistep in a loop, and the message only occurs for some of the datasets. I cannot include a reproducible sample - the specific datasets where this is occur ing are fairly large and there are several pcnm's in the rhs of the formula. thanks for any pointers that may allow me to
2009 Nov 05
3
performing operations on a dataframe
Hey all, I feel like the solution to this problem should be relatively simple, but for some reason I can't find answers or come up with my own solution. Given the dataframe: (SpA and SpB not important, want to look at distribution of cooccurance for each year) Year SpA SpB Coocc 2000 0 2000 2 2000 1 2001 8 2001 2 2001 0 2001 0 2002 1 2002 2 How can I apply different functions to
2011 Nov 07
2
adjusting levelplot color scale to data
Hi guys, I have a matrix with values varying from approximately -0.7 to 0.33 that I want to create a heatmap/levelplot with. When I execute the levelplot function for my matrix, I end up getting colors that are adjusted to the max and min rather than around 0. In other words, ideally I would like to have a color ramp that goes from red (negative number), to white (0), to blue (positive);
2020 Oct 31
2
raster::levels() not working in packaged function.
Apologies, I cannot see how to make a rero for this issue. I have a function that uses levels(r) tor return the RAT of a raster "r" when the function is sourced from a script source(".\R\function.r") it works fine. when the function is built into a package and sourced from there library(mypackage) using the same script file to make the package levels(r)[[1]] the same line
2012 Mar 29
1
Retrieving matrix column and row names by index value
Hi all, So let's say I have a matrix, mdat and I only know the index number. How do I retrieve the column and row names? For example, > mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE, dimnames = list(c("row1", "row2"), c("C.1", "C.2", "C.3"))) > mdat[4] [1] 12 >
2010 Oct 12
2
repeatability/intraclass with nested levels
I have a spectrophotometric dataset with repeated measures of a value at 200 wavelengths for each of 150 individuals. I would like to use the repeated samples to at each wavelength to look at measurement/observer error, compared to difference between individuals error I have looked at doing this with icc{irr} or using an anova approach, but I am unclear how to acheive this given that there
2011 Dec 03
1
partial mantel tests in ecodist with intential NA values.
I would like to perform partial mantel tests on only within group values, with "between group" values assigned to NA. This is possible in package ncf partial.mantel.test, however this sues a different permutation to that used in ecodist.ecodist will not accept data with NA values, returning a "matrix is not square error. is it possible to perform this test in ecodist? many thanks
2010 Apr 29
5
reduce size of pdf
is there a way to reduce the size of pdf files in R: ? compression? lower dpi ? or some other option?
2010 Dec 17
1
Change legend position in s.value {ade4}
How do I change the postion of the legend in s.value {ade4} from the defaul , bootom left? thanks Nevil Amos
2010 May 07
1
writing string values from a matrix to a file without enclosing quotes
I am trying to format data for the Geneland package I need to write a series of paired numbers and paired "000" to a plain ascii file without surrounding the numerals with quotes, the original data is in a matrix formatted paired strings, and written to file using write.table(x,"output filename",col.names=F,row.names=F) thus "77 79" "132 132" "000