Re: [R] Declare BASH Array Using R System Function
You seem confused. You are programming in R, and asking questions about bash on an R mailing list. You seem to need to learn the difference between environment variables and bash variables and how processes acquire and transfer environment variables, which is really an operating system concept and off topic here. Once you do understand this difference, you might be interested in reading the R help file on Sys.setenv(). --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Dario Strbenac wrote: >Hello, > >It is difficult searching for previous posts about this since the >keywords are short and ambiguous, so I hope this is not a duplicate >question. > >I can easily declare an array on the command line. > >$ names=(X Y) >$ echo ${names[0]} >X > >I am unable to do the same from within R. > >> system("names=(X Y)") >sh: Syntax error: "(" unexpected > >Reading the documentation for the system function, it appears to only >be relevant for executing commands. What can I do instead to declare a >BASH array ? Thanks. > >-- >Dario Strbenac >PhD Student >University of Sydney >Camperdown NSW 2050 >Australia > >__ >R-help@r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R function
Dear R users; I am MSc student and I want to write my own function, but it cant be completed. please help me for solve it. here is my code: pah1$P = (pah1$Fluoranthene/pah1$Pyrene) T = function(x){ for (i in 1:length(pah1$P)) if (i >= 1) print("Combustion") if (i < 1) print("Petroleum") } T(pah1$P[c(1:83),]) I wish that R gives me a column that if value greater or equal to one give "Combustion" and if value is less than one give "Petroleum". but my function dose not work. thank you so much for your help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] surface plot
Dear R users; I have a question about surface plot that show me spatial variability of parameter. I have a data frame with 6 variables and X and Y for coordinate system. X Y pH ..... ... so I want to create a surface plot for my data. please help me. many thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Declare BASH Array Using R System Function
Hello, It is difficult searching for previous posts about this since the keywords are short and ambiguous, so I hope this is not a duplicate question. I can easily declare an array on the command line. $ names=(X Y) $ echo ${names[0]} X I am unable to do the same from within R. > system("names=(X Y)") sh: Syntax error: "(" unexpected Reading the documentation for the system function, it appears to only be relevant for executing commands. What can I do instead to declare a BASH array ? Thanks. -- Dario Strbenac PhD Student University of Sydney Camperdown NSW 2050 Australia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with prefmod
Hello, I'm using the prefmod package, with pattPC fit, and I'm having some trouble interpreting the results. I am giving two different species of animal a choice between two of three different patterns, V, H, and 45. I have run a number of paired tests with different combinations of the above, and my outputs are as follows: estimate sez p-value V 0.07196 0.18992 0.379 0.7047 H 0.10790 0.19009 0.568 0.5700 V:Species2 0.17084 0.24317 0.703 0.4821 H:Species2 0.13490 0.23965 0.563 0.5734 U -0.934680.19993 -4.675 0. I'm assuming that the baseline is the 45 measurement, but I'm not sure what the category titled "U" refers to? In my model this is particularly interesting as the other p-values are quite high, but the U p-value is 0.003. I haven't been able to find any information about this online thus far. Thank you, Qamar Qamar Schuyler PhD Research Student University of Queensland Moreton Bay Research Station Dunwich, QLD 4183 Mobile: +61 4 275 66868 Work: +61 7 3409 9058 Fax: +61 7 3409 9839 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] MCMClogit: Cannot calculate marginal likelihood with improper prior
I'm an undergrad who is new to MCMCpack and I haven't been able to find an answer to my problem online yet: I'm attempting to run MCMClogit with a Cauchy proper prior but I'm getting the warning "Cannot calculate marginal likelihood with improper prior" (my purposes require the marginal likelihood calculation so I understand that I need to use a proper prior). I'm trying to simulate the "user-defined independent Cauchy prior with additional args" as specified in the MCMCpack User Manual (p. 76, April 2013 version). My input data has been standardized (mean = 0, sd = 0.5 for non-binary variables, and binary variables with mean of 0 and difference of 1 between upper and lower ends) according to the Gelman 2008 paper on logistic regression (www.stat.columbia.edu/~gelman/research/published/priors11.pdf). When I run the example data set (birthwt) from the User Manual, the logpriorfun works correctly allowing the marginal likelihood to be generated. However, when I try running my data with the logprior fun, I get a warning that the prior is improper. Here is the code I am running: *logpriorfun = function(beta, location,scale){ sum(dcauchy(beta, location, scale, log = TRUE)) }* *> MCMC.2= MCMClogit(DEAD ~ YEARS + MALE + x1 + x2 + x3+ x4 +x5 + x6 + x7 + x8 + x9, tune= 0.65,burnin =500, mcmc=5000, data = dat, marginal.likelihood = "Laplace", user.prior.density=logpriorfun, logfun=TRUE, location = 0, scale=2.5) * *@ The Metropolis acceptance rate was 0.27418 @ Warning message: In MCMClogit(DEAD ~ YEARS + MALE + x1 + x2 + x3 + : Cannot calculate marginal likelihood with improper prior* Any advice on how to fix my arguments so it is a proper prior and will allow me to generate a marginal likelihood using the Laplace approximation? Or how should I be coding a Cauchy proper prior? I'm having problems defining the priors. Thanks, B. -- View this message in context: http://r.789695.n4.nabble.com/MCMClogit-Cannot-calculate-marginal-likelihood-with-improper-prior-tp4672561.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Chinese characters in html source captured by download.file() are garbled code , how to convert it readable
Dear list, I am working with R to download numerous html source code from which the data extracted will be further processed. The problem is the Chinese character in the html source code are all garbled and I can't really find a way to convert them to something readable. This problem persists on ubuntu-10 and win-7, English environment. Not try Operating system in Chinese yet. I know literally nothing about encoding and a comprehensive search online does not save me from this woe. # the code download.file(" https://www.google.com.hk/finance/company_news?q=SHA:601857&gl=cn&num=200 ",destfile="tmp.txt") test<-readLines("tmp.txt",encoding="UTF-8") #the garbled code in "tmp.txt" and "test" is like below #��国�۪o�ѵM�a�ѥ��������q�]� Any help is highly appreciated. yong [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot position_dodge requires constant width
Hi, This link may help: http://stackoverflow.com/questions/14476961/why-do-i-get-position-dodge-requires-constant-width-even-though-widths-are-con A.K. - Original Message - From: David Arnold To: r-help@r-project.org Cc: Sent: Sunday, July 28, 2013 5:41 PM Subject: [R] ggplot position_dodge requires constant width Hi, library(ggplot2,plyr) qplot(carat,depth,data=diamonds, geom="boxplot", group=round_any(carat,0.1,floor), xlim=c(0,3)) Typing: warnings() Gives me: Warning messages: 1: position_dodge requires constant width: output may be incorrect How should the above code be adjusted to avoid this warning? Curious, as this code is copied directly from ggplot2 Elegant Graphics for Data Analysis. D. -- View this message in context: http://r.789695.n4.nabble.com/ggplot-position-dodge-requires-constant-width-tp4672559.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ggplot position_dodge requires constant width
Hi, library(ggplot2,plyr) qplot(carat,depth,data=diamonds, geom="boxplot", group=round_any(carat,0.1,floor), xlim=c(0,3)) Typing: warnings() Gives me: Warning messages: 1: position_dodge requires constant width: output may be incorrect How should the above code be adjusted to avoid this warning? Curious, as this code is copied directly from ggplot2 Elegant Graphics for Data Analysis. D. -- View this message in context: http://r.789695.n4.nabble.com/ggplot-position-dodge-requires-constant-width-tp4672559.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting Current and Old Date
Hi, ?max ?min max(mydates) #[1] "2007-06-22" min(mydates) #[1] "2004-02-13" max(mydates)-min(mydates) Time difference of 1225 days max(as.numeric(mydates))-min(as.numeric(mydates)) #[1] 1225 A.K. - Original Message - From: Peter Maclean To: "r-help@r-project.org" Cc: Sent: Sunday, July 28, 2013 3:20 PM Subject: Re: [R] Extracting Current and Old Date #This my look trivial but has been killing my time #I want to extract most current and old date from mydates #variable that has more than 10,000 observation. #Get days # use as.Date( ) to convert strings to dates mydates <- as.Date(c("2007-06-22", "2007-05-21", "2004-04-13", "2004-03-11","2004-02-13",)) #Is there a way/fuction to extract mostcurrent date #from mydates variable mostcurrent <- as.Date(c("2007-06-22")) #Is there a way/function to extract olddate #from mydates variable olddate <- as.Date(c("2004-02-13")) #Days between most current and old dayte days <- as.numeric(mostcurrent - olddate) Peter Maclean Department of Economics UDSM [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting Current and Old Date
On Jul 28, 2013, at 12:20 PM, Peter Maclean wrote: > #This my look trivial but has been killing my time > #I want to extract most current and old date from mydates #variable that has > more than 10,000 observation. > #Get days > # use as.Date( ) to convert strings to dates > mydates <- as.Date(c("2007-06-22", "2007-05-21", "2004-04-13", > "2004-03-11","2004-02-13",)) > #Is there a way/fuction to extract mostcurrent date > #from mydates variable > mostcurrent <- as.Date(c("2007-06-22")) > > #Is there a way/function to extract olddate > #from mydates variable > olddate<- as.Date(c("2004-02-13")) > > #Days between most current and old dayte > days <- as.numeric(mostcurrent - olddate) The usual ways to work with numeric data have been given .Date methods: > mydates <- as.Date(c("2007-06-22", "2007-05-21", "2004-04-13", > "2004-03-11","2004-02-13")) > min(mydates) [1] "2004-02-13" > max(mydates) [1] "2007-06-22" > range(mydates) [1] "2004-02-13" "2007-06-22" > diff(range(mydates)) Time difference of 1225 days -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting Current and Old Date
If I read this correctly: mydates <- as.Date(c("2007-06-22", "2007-05-21", "2004-04-13", "2004-03-11","2004-02-13")) xx <- min(mydates) yy <- max(mydates) yy-xx John Kane Kingston ON Canada > -Original Message- > From: pmaclean2...@yahoo.com > Sent: Sun, 28 Jul 2013 12:20:30 -0700 (PDT) > To: r-help@r-project.org > Subject: Re: [R] Extracting Current and Old Date > > #This my look trivial but has been killing my time > #I want to extract most current and old date from mydates #variable that > has more than 10,000 observation. > #Get days > # use as.Date( ) to convert strings to dates > mydates <- as.Date(c("2007-06-22", "2007-05-21", "2004-04-13", > "2004-03-11","2004-02-13",)) > #Is there a way/fuction to extract mostcurrent date > #from mydates variable > mostcurrent <- as.Date(c("2007-06-22")) > > #Is there a way/function to extract olddate > #from mydates variable > olddate<- as.Date(c("2004-02-13")) > > #Days between most current and old dayte > days <- as.numeric(mostcurrent - olddate) > > > Peter Maclean > Department of Economics > UDSM > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. GET FREE 5GB EMAIL - Check out spam free email with many cool features! Visit http://www.inbox.com/email to find out more! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting Current and Old Date
#This my look trivial but has been killing my time #I want to extract most current and old date from mydates #variable that has more than 10,000 observation. #Get days # use as.Date( ) to convert strings to dates mydates <- as.Date(c("2007-06-22", "2007-05-21", "2004-04-13", "2004-03-11","2004-02-13",)) #Is there a way/fuction to extract mostcurrent date #from mydates variable mostcurrent <- as.Date(c("2007-06-22")) #Is there a way/function to extract olddate #from mydates variable olddate <- as.Date(c("2004-02-13")) #Days between most current and old dayte days <- as.numeric(mostcurrent - olddate) Peter Maclean Department of Economics UDSM [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] variable bandwidths in R
Inline. On Sun, Jul 28, 2013 at 10:38 AM, Rui Barradas wrote: > Hello, > > You should Cc the list, the odds of getting more and better answers is > greater. > I don't believe what you want is statistically sound, why more than one > bandwidth? Anyway, if density() doesn't do what you need, you can try to > look for similar functions in other packages. Try the following. > > library(sos) > > findFn('kernel density estimation') > > > There are several hits with 'kde' in the name of the function. But I doubt > they implement multiple bandwidths per call. I agree. Trying adding "adaptive" to your search (e.g. "adaptive smoothing", "adaptive density estimation" or whatever. -- Bert > > Rui Barradas > > Em 28-07-2013 16:11, Ms khulood aljehani escreveu: >> >> >> Hi >> Thank You for your help >> >> I tried this way, bw argument allowed to one value >> I want more than one value, and this values change as the observation in >> the original vector change >> >> Thank You >> >>> Date: Sun, 28 Jul 2013 10:33:35 +0100 >>> From: ruipbarra...@sapo.pt >>> To: aljehan...@hotmail.com >>> CC: r-h...@stat.math.ethz.ch >>> Subject: Re: [R] variable bandwidths in R >>> >>> Hello, >>> >>> Try function ?density, argument bw, in package stats. >>> >>> Hope this helps, >>> >>> Rui Barradas >>> >>> Em 28-07-2013 04:18, Ms khulood aljehani escreveu: HelloI want to know how can implement variable bandwidths for kernel density estimation in R. What the packages that I need to use? And what the command? Thank You Khulood H. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. >> >> > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] variable bandwidths in R
Hello, You should Cc the list, the odds of getting more and better answers is greater. I don't believe what you want is statistically sound, why more than one bandwidth? Anyway, if density() doesn't do what you need, you can try to look for similar functions in other packages. Try the following. library(sos) findFn('kernel density estimation') There are several hits with 'kde' in the name of the function. But I doubt they implement multiple bandwidths per call. Rui Barradas Em 28-07-2013 16:11, Ms khulood aljehani escreveu: Hi Thank You for your help I tried this way, bw argument allowed to one value I want more than one value, and this values change as the observation in the original vector change Thank You Date: Sun, 28 Jul 2013 10:33:35 +0100 From: ruipbarra...@sapo.pt To: aljehan...@hotmail.com CC: r-h...@stat.math.ethz.ch Subject: Re: [R] variable bandwidths in R Hello, Try function ?density, argument bw, in package stats. Hope this helps, Rui Barradas Em 28-07-2013 04:18, Ms khulood aljehani escreveu: HelloI want to know how can implement variable bandwidths for kernel density estimation in R. What the packages that I need to use? And what the command? Thank You Khulood H. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Replacing NA values solved
Hi all, Tnx for all the replies: Mike Colvin provided a simple answer in one step. Bats.cast <- dcast(data = Bats.melt, formula = Species ~ Location, fill =0) tnx all for the reminder of potential issues of willy nilly replacing missing data with zeros. In this case the 0 [zero value] for NAs is correct in this application as the NAs do not represent "missing data" but actually no occurrence of a critter in a given habitat location so the values need to be a 0. Tnx again, Bruce -- Bruce W. Miller, PhD. Neotropical bat risk assessments If we lose the bats, we may lose much of the tropical vegetation and the lungs of the planet Using acoustic sampling to map species distributions for >15 years. Providing Interactive identification keys to the vocal signatures of New World Bats For various project details see: https://sites.google.com/site/batsoundservices/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to replace NA values
Hi all, I am using reshape2 to reformat a data frame and all is great using: Bats.melt <- melt(data = Bats) Bats.cast <- dcast(data = Bats.melt, formula = Species ~ Location) dput(Bats.cast,'C:/=Bat data working/Nica_new/Bats_niche.robj') write.csv(Bat.cast,'C:/=Bat data working/Nica_new/test_Niche.csv') The resulting file from both dput and write are great, however in order to run another R analysis I need to replace all the NA values in the output with a zero - 0 value. I have just been opening this in Excel and using a simple find NA replace with 0 and saving then reopening in R. There must be a simple way to do this in R. Any suggestions welcomed. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace NA values
The mechanics of replacing missing values are very easy in R > tmp <- data.frame(a=1:4,b=c(5,6,NA,8)) > tmp a b 1 1 5 2 2 6 3 3 NA 4 4 8 > tmp[is.na(tmp)] <- 0 > tmp a b 1 1 5 2 2 6 3 3 0 4 4 8 > But pay attention to Bert's warning. This is most likely the wrong statistical way to respond to the missing values. Rich On Sun, Jul 28, 2013 at 9:19 AM, Neotropical bat risk assessments < neotropical.b...@gmail.com> wrote: > Hi all, > > I am using reshape2 to reformat a data frame and all is great using: > > Bats.melt <- melt(data = Bats) > > Bats.cast <- dcast(data = Bats.melt, formula = Species ~ Location) > > dput(Bats.cast,'C:/=Bat data working/Nica_new/Bats_niche.robj') > > write.csv(Bat.cast,'C:/=Bat data working/Nica_new/test_Niche.csv') > > > The resulting file from both dput and write are great, however in order > to run another R analysis I need to replace all the NA values in the > output with a zero - 0 value. > > I have just been opening this in Excel and using a simple find NA > replace with 0 and saving then reopening in R. > > There must be a simple way to do this in R. > > Any suggestions welcomed. > > > > -- > Bruce W. Miller, PhD. > Neotropical bat risk assessments > > If we lose the bats, we may lose much of the tropical vegetation and the > lungs of the planet > > Using acoustic sampling to map species distributions for >15 years. > > Providing Interactive identification keys to the vocal signatures of New > World Bats > > For various project details see: > > https://sites.google.com/site/batsoundservices/ > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace NA values
Inline. --Bert On Sun, Jul 28, 2013 at 6:19 AM, Neotropical bat risk assessments wrote: > Hi all, > > I am using reshape2 to reformat a data frame and all is great using: > > Bats.melt <- melt(data = Bats) > > Bats.cast <- dcast(data = Bats.melt, formula = Species ~ Location) > > dput(Bats.cast,'C:/=Bat data working/Nica_new/Bats_niche.robj') > > write.csv(Bat.cast,'C:/=Bat data working/Nica_new/test_Niche.csv') > > > The resulting file from both dput and write are great, however in order > to run another R analysis I need to replace all the NA values in the > output with a zero - 0 value. I strongly suspect this is false. Most R functions have options to deal with NA, alas, not consistently though. See, e.g. ?na.omit . For manual processing, see ?NA (of course!). However, replacing NA's with 0's is dangerous. It may also be scientifically/statistically flawed; although properly dealing with missing data can be a very difficult issue. Cheers, Bert > > I have just been opening this in Excel and using a simple find NA > replace with 0 and saving then reopening in R. > > There must be a simple way to do this in R. > > Any suggestions welcomed. > > > > -- > Bruce W. Miller, PhD. > Neotropical bat risk assessments > > If we lose the bats, we may lose much of the tropical vegetation and the > lungs of the planet > > Using acoustic sampling to map species distributions for >15 years. > > Providing Interactive identification keys to the vocal signatures of New > World Bats > > For various project details see: > > https://sites.google.com/site/batsoundservices/ > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to replace NA values
Hi all, I am using reshape2 to reformat a data frame and all is great using: Bats.melt <- melt(data = Bats) Bats.cast <- dcast(data = Bats.melt, formula = Species ~ Location) dput(Bats.cast,'C:/=Bat data working/Nica_new/Bats_niche.robj') write.csv(Bat.cast,'C:/=Bat data working/Nica_new/test_Niche.csv') The resulting file from both dput and write are great, however in order to run another R analysis I need to replace all the NA values in the output with a zero - 0 value. I have just been opening this in Excel and using a simple find NA replace with 0 and saving then reopening in R. There must be a simple way to do this in R. Any suggestions welcomed. -- Bruce W. Miller, PhD. Neotropical bat risk assessments If we lose the bats, we may lose much of the tropical vegetation and the lungs of the planet Using acoustic sampling to map species distributions for >15 years. Providing Interactive identification keys to the vocal signatures of New World Bats For various project details see: https://sites.google.com/site/batsoundservices/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] repeated measures logistic regression
Thanks very much Ben for your extremely helpful response. I have loads of data so this worked fine. cheers, Stan On Saturday, July 27, 2013, Ben Bolker wrote: > Stanislav Aggerwal gmail.com> writes: > > > > > I have searched the r-help archive and saw only one > > unanswered post related > > to mine. > > Take a look at the r-sig-mixed-models (@r-project.org) > mailing list and archive ... > > > > My design is as follows. > > > >- y is Bernoulli response > >- x1 is continuous variable > >- x2 is categorical (factor) variable with two levels > > > > The experiment is completely within subjects. That is, each subject > > receives each combination of x1 and x2. > > > > This is a repeated measures logistic regression set-up. > > The experiment will > > give two ogives for p(y==1) vs x1, one for level1 and one > > for level2 of x2. > > The effect of x2 should be that for level2 compared to level1, the ogive > > should have a shallower slope and increased intercept. > > > I am struggling with finding the model using lme4. Here is a guess at it: > > > > glmer(y~x1*x2 +(1|subject),family=binomial) > > > So far as I understand it, the 1|subject part says > > that subject is a random > > effect. But I do not really understand the notation or > > how to specify that x1 and x2 are repeated measures variables. > > In the end I want a model that > > includes a random effect for subjects, and gives estimated slopes and > > intercepts for level1 and level2. > > I believe you want > > glmer(y~x1*x2 +(x1*x2|subject),family=binomial,data=...) > > (I strongly recommend including the data= argument in your call) > > This will give a population-level estimate of > > intercept (log-odds in group 1 at x1=0) > treatment effect on intercept (log-odds(level2,x1=0)-log-odds(level1,x=0)) > log-odds slope in level 1 > difference in slopes > > as well as among-individual variances in all four of these parameters, > and covariances among all the parameters (i.e. a 4x4 variance-covariance > matrix for these parameters). > > For binary data and estimating 4 fixed + 10 RE parameters > (i.e., variances and covariances), you're going to need a lot of data -- > very conservatively, 140 total observations. > > It may help to center your x1 variable. > > see http://glmm.wikidot.com/faq > (especially http://glmm.wikidot.com/faq#modelspec), > and the r-sig-mixed-models mailing list. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] variable bandwidths in R
Hello, Try function ?density, argument bw, in package stats. Hope this helps, Rui Barradas Em 28-07-2013 04:18, Ms khulood aljehani escreveu: HelloI want to know how can implement variable bandwidths for kernel density estimation in R. What the packages that I need to use? And what the command? Thank You Khulood H. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Boxcox transformation error
On Jul 27, 2013, at 00:00 , Miller Ruiz wrote: > Hello > > I'm trying to run the script below for making a boxcox transformation of > some variables contained on an excel file, but i can't get it. I ever have > the same message : > error : $ operator is invalid for atomic vectors > > One of the names of the variables is "Ec30" and it's the variable I put as > example. > > require(RODBC) > require(fBasics) > require(e1071) > require(MASS) > setwd("C:\\estadisticafijo") > dir() > temp=odbcConnectExcel("prueba35r") > rs<-sqlFetch(temp,"Hoja1") > close(temp) > fix(rs) > boxcox(rs$"Ec30") > > Thaks a lot for your help. The most obvious guess is that "rs" isn't what you think it should be, so how about showing us the result of str(rs)? -pd -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] variable bandwidths in R
HelloI want to know how can implement variable bandwidths for kernel density estimation in R. What the packages that I need to use? And what the command? Thank You Khulood H. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Duplicated function with conditional statement
Dear Arun,, Thank you. its perfect! wow! thank you very much..and David, thank you for you too.. its such a help. I am so sorry it must've been confusing at the beginning.. really, I dont know how to thank you.. well do you mind if I ask you how can you be so expert? what kind a book or training did you have? and how long have you been working on R? I am really interested in R On Sun, Jul 28, 2013 at 2:40 AM, arun wrote: > If you wanted to wrap it in a function: > > > fun1<- function(dat,colName,newColumn){ > indx<- which(dat[,colName]=="buy") > dat[,newColumn]<-0 > dat[unique(unlist(lapply(seq_along(indx),function(i){ > x1<- if(i==length(indx)){ > seq(indx[i],nrow(dat)) > } > else if((indx[i+1]-indx[i])==1){ > indx[i] > } > else { > seq(indx[i]+1,indx[i+1]-1) > } > x2<- dat[unique(c(indx[i:1],x1)),] > x3<- subset(x2,response=="sample") > x4<- subset(x2,response=="buy") > x4New<-x4[order(as.numeric(row.names(x4))),] > x5<- row.names(x4New)[duplicated(x4New$product)] > x6<- if(nrow(x3)!=0) { > row.names(x3)[x3$product%in% x4$product] >} > > sort(as.numeric(c(x5,x6))) > }))),newColumn] <- 1 > dat > > } > > > fun1(tt1,"response","newCol") > # subj response product newCol > #1 1 sample 1 0 > #2 1 sample 2 0 > #3 1 buy 3 0 > #4 2 sample 2 0 > #5 2 buy 2 0 > #6 3 sample 3 1 > #7 3 sample 2 1 > #8 3 buy 1 0 > #9 4 sample 1 1 > #104 buy 4 0 > #115 buy 4 1 > #125 sample 2 1 > #135 buy 2 1 > #146 buy 4 1 > #156 sample 5 0 > #166 sample 5 0 > #177 sample 4 1 > #187 buy 3 1 > #197 buy 4 1 > #208 buy 5 0 > #218 sample 4 1 > #228 buy 2 1 > > A.K. > > > - Original Message - > From: arun > To: vanessa van der vaart > Cc: David Winsemius ; R help > > Sent: Saturday, July 27, 2013 9:11 PM > Subject: Re: [R] Duplicated function with conditional statement > > HI, > May be this is what you wanted. > #using tt1 > indx<-which(tt1$response=="buy") > tt1$newcolumn<-0 > tt1[unique(unlist(lapply(seq_along(indx),function(i){x1<-if(i==length(indx)) > seq(indx[i],nrow(tt1)) else if((indx[i+1]-indx[i])==1) indx[i] else > seq(indx[i]+1,indx[i+1]-1);x2<- > tt1[unique(c(indx[1:i],x1)),];x3<-subset(x2,response=="sample");x4<- > subset(x2,response=="buy"); > x5<-row.names(x4)[duplicated(x4$product)];x6<-if(nrow(x3)!=0) > row.names(x3)[x3$product%in% x4$product];sort(c(x5,x6))}))),"newcolumn"]<-1 > > > tt1 >subj response product newcolumn > 1 1 sample 1 0 > 2 1 sample 2 0 > 3 1 buy 3 0 > 4 2 sample 2 0 > 5 2 buy 2 0 > 6 3 sample 3 1 > 7 3 sample 2 1 > 8 3 buy 1 0 > 9 4 sample 1 1 > 104 buy 4 0 > 115 buy 4 1 > 125 sample 2 1 > 135 buy 2 1 > 146 buy 4 1 > 156 sample 5 0 > 166 sample 5 0 > 177 sample 4 1 > 187 buy 3 1 > 197 buy 4 1 > 208 buy 5 0 > 218 sample 4 1 > 228 buy 2 1 > A.K. > > > > > > > From: vanessa van der vaart > To: arun > Cc: David Winsemius ; R help > > Sent: Saturday, July 27, 2013 6:55 PM > Subject: Re: [R] Duplicated function with conditional statement > > > > Dear all,, > thank you all for your help..Its been such a help but its not really > exactly what I am looking for. Apparently I havent explained the condition > very clearly. I hope this can works. > > If the data on column product is duplicated from the previous row, (its > applied for response==buy and ==sample) , and it is duplicated from the row > which has the value on column 'response'== buy, than the value = 1, > otherwise is =0. > so in that case, > if the value is duplicated but it is duplicated from the previous row > where the value of resonse==sample, than it is not considered duplicated, > and in the new column is 0 > > thank you very much in advance, > I really appreciated > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE