[R] deconstructing curve into rising and falling limbs
hello, I have some data that looks similar to this (only not as nice as this): Y <- c(abs(rnorm(100, 0.10, .1)), seq(.10, 1.0, .3)+rnorm(1, 0, .5) , seq(0.8, 4.0, .31)+rnorm(1, 0, .5) , seq(3.9, .20, -.2)+rnorm(1, 0, .5) , abs(rnorm(100, 0.13, .1)) , seq(.10, 1.2, .35)+rnorm(1, 0, .5) , seq(0.7, 6.0, .31)+rnorm(1, 0, .5) , seq(5.9, .23, -.18)+rnorm(1, 0, .5) , abs(rnorm(50, 0.18, .1)) ) plot(Y~c(1:length(Y))) # it is water level through time I am trying to find a way to divide these data into 3 sections , 1) the rising limbs, 2) falling limbs, and 3) not #1 or #2. I'll spare you the list of things I've tried, just know that the data is generally too noisy to use something as simple as which(diff(Y) > b), where b is some threshold. Please let me know if you have an idea of how to tackle this. -- View this message in context: http://r.789695.n4.nabble.com/deconstructing-curve-into-rising-and-falling-limbs-tp4647512.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] deconstructing curve into rising and falling limbs
Thanks Jean, Your 1st solution was one I've tried, w/o great success. The 2nd works a lot better (on real, and more messy, data), especially when I set span to a much smaller number than 1/10. Thank you greatly. -Chuck Jean V Adams wrote > Using the data you provided, a combination of slope and height comes > close: > > X <- seq(Y) > high <- Y > 0.6 > > upslope <- c(FALSE, diff(Y) > 0) > section <- rep(1, length(Y)) > section[upslope==TRUE & high==TRUE] <- 2 > section[upslope==FALSE & high==TRUE] <- 3 > plot(X, Y, col=section) > > > Or you could base the slope on the a smooth fit of the data rather than Y > itself: > > P <- loess(Y ~ X, degree=2, span=1/10)$fitted > > upslope <- c(FALSE, diff(P) > 0) > section <- rep(1, length(Y)) > section[upslope==TRUE & high==TRUE] <- 2 > section[upslope==FALSE & high==TRUE] <- 3 > plot(X, Y, col=section) > > Jean > > > > "chuck.01" < > CharlieTheBrown77@ > > wrote on 10/26/2012 03:14:29 AM: >> >> hello, >> I have some data that looks similar to this (only not as nice as this): >> >> Y <- c(abs(rnorm(100, 0.10, .1)), seq(.10, 1.0, .3)+rnorm(1, 0, .5) , >> seq(0.8, 4.0, .31)+rnorm(1, 0, .5) >> , seq(3.9, .20, -.2)+rnorm(1, 0, .5) , abs(rnorm(100, 0.13, .1)) , > seq(.10, >> 1.2, .35)+rnorm(1, 0, .5) >> , seq(0.7, 6.0, .31)+rnorm(1, 0, .5) , seq(5.9, .23, -.18)+rnorm(1, 0, > .5) , >> abs(rnorm(50, 0.18, .1)) ) >> >> plot(Y~c(1:length(Y))) # it is water level through time >> >> I am trying to find a way to divide these data into 3 sections , 1) the >> rising limbs, 2) falling limbs, and 3) not #1 or #2. >> I'll spare you the list of things I've tried, just know that the data is >> generally too noisy to use something as simple as which(diff(Y) > b), > where >> b is some threshold. >> Please let me know if you have an idea of how to tackle this. > > [[alternative HTML version deleted]] > > __ > R-help@ > 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. -- View this message in context: http://r.789695.n4.nabble.com/deconstructing-curve-into-rising-and-falling-limbs-tp4647512p4647550.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] Which test should I use for comparing the change of two samples
1) get differences 2) run t-test on #1 * Be warned: I am not a statistician. Tammy Ma wrote > Dear All, > > I have two samples as the following: > conjps<-c(9.41,10.45,10.78,10.73,11.11,11.12,11.59,11.04,11.63) > > ms<-c(4.11,5.10,5.70,6.46,6.04,6.16, 6.24,6.32,7.33) > > I want to test the change of sample is same to the another one. > conjps_ch<-c(1.04,0.33.) > ms<-c(0.99,0.60,0.76) > > > which test I should use, which conclusion can we drive based on the test? > > I used the following test: > > > Test Equality > of Two Variances > > F > test to compare two variances > > > > data: > conjps and ms > > F = 0.5419, num df = 8, > denom df = 8, > p-value = 0.4045 > > alternative hypothesis: true ratio of > variances is not equal to 1 > > 95 percent confidence interval: > > 0.1222368 2.4024170 > > sample estimates: > > ratio of variances > > > 0.5419076 > > > > is it correct? which conclusion can I get based on this? > > > Thanks for help. > > Kind regards, > Tammy > > [[alternative HTML version deleted]] > > > __ > R-help@ > 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. -- View this message in context: http://r.789695.n4.nabble.com/Which-test-should-I-use-for-comparing-the-change-of-two-samples-tp4647756p4647798.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] changing date by +/- days
got it, sorry! structure(1243792800, class = c("POSIXct", "POSIXt"), tzone = "GMT")-(60*60*24*10) chuck.01 wrote > Hi, > Let say I have a date variable like this: > > structure(1243792800, class = c("POSIXct", "POSIXt"), tzone = "GMT") > [1] "2009-05-31 18:00:00 GMT" > > How can I make it 10 days prior, so: > [1] "2009-05-21 18:00:00 GMT" > > I'm randomly selecting dates from a list and want a second value a set # > of days either before or after. > > Thanks ahead of time. -- View this message in context: http://r.789695.n4.nabble.com/changing-date-by-days-tp4647803p4647804.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] changing date by +/- days
Hi, Let say I have a date variable like this: structure(1243792800, class = c("POSIXct", "POSIXt"), tzone = "GMT") [1] "2009-05-31 18:00:00 GMT" How can I make it 10 days prior, so: [1] "2009-05-21 18:00:00 GMT" I'm randomly selecting dates from a list and want a second value a set # of days either before or after. Thanks ahead of time. -- View this message in context: http://r.789695.n4.nabble.com/changing-date-by-days-tp4647803.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] POSIXct date missing "time component"
Um, OK. My dates have times, they are 00:00:00 (i.e. midnight) I'll just add a fraction of a second my dates and go with it. Thanks for the reply. arun kirshna wrote > HI, > Please check this link > (http://rss.acs.unt.edu/Rdoc/library/base/html/as.POSIXlt.html). > "Dates without times are treated as being at midnight UTC. " > > May be you can try this (if it doesn't create additional problems): > dates.mine2<-dates.mine+1 > dates.mine2 > #[1] "2009-05-21 23:30:01 GMT" "2009-05-21 23:45:01 GMT" > #[3] "2009-05-22 00:00:01 GMT" "2009-05-22 00:15:01 GMT" > dates.mine2[3] > #[1] "2009-05-22 00:00:01 GMT" > str(dates.mine2) > #POSIXct[1:4], format: "2009-05-21 23:30:01" "2009-05-21 23:45:01" ... > A.K. -- View this message in context: http://r.789695.n4.nabble.com/POSIXct-date-missing-time-component-tp4647932p4647939.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] POSIXct date missing "time component"
Hi, I have some dates that are giving me a problem, in general the dates look like this: free.dates[60:61] [1] "2009-05-21 23:45:00 GMT" "2009-05-22 00:00:00 GMT" but for some reason, when taken "alone", they look like this: free.dates[60] [1] "2009-05-21 23:45:00 GMT" free.dates[61] [1] "2009-05-22 GMT" # the time component is gone, and doesn't jive with other code I have written. Here are those two data points: dates.mine <- dput(free.dates[60:61]) structure(c(1242949500, 1242950400), class = c("POSIXct", "POSIXt"), tzone = "GMT") Any idea how I can force this to include the time component? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/POSIXct-date-missing-time-component-tp4647932.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] POSIXct date missing "time component"
I suppose I should add that this happens at midnight Some more of the data: dates.mine <- dput(free.dates[59:62]) structure(c(1242948600, 1242949500, 1242950400, 1242951300), class = c("POSIXct", "POSIXt"), tzone = "GMT") dates.mine [1] "2009-05-21 23:30:00 GMT" "2009-05-21 23:45:00 GMT" [3] "2009-05-22 00:00:00 GMT" "2009-05-22 00:15:00 GMT" dates.mine[3] [1] "2009-05-22 GMT" chuck.01 wrote > Hi, > > I have some dates that are giving me a problem, in general the dates look > like this: > > free.dates[60:61] > [1] "2009-05-21 23:45:00 GMT" "2009-05-22 00:00:00 GMT" > > but for some reason, when taken "alone", they look like this: > free.dates[60] > [1] "2009-05-21 23:45:00 GMT" > > free.dates[61] > [1] "2009-05-22 GMT" # the time component is gone, and doesn't jive with > other code I have written. > > Here are those two data points: > > dates.mine <- dput(free.dates[60:61]) > structure(c(1242949500, 1242950400), class = c("POSIXct", "POSIXt"), tzone > = "GMT") > > > Any idea how I can force this to include the time component? > Thanks! -- View this message in context: http://r.789695.n4.nabble.com/POSIXct-date-missing-time-component-tp4647932p4647933.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] POSIXct date missing "time component"
I did not read that close enough; thanks again. arun kirshna wrote > Hi, > > ?as.POSIXct() > format: character string giving a date-time format as used by > ‘strptime’. > > ?strptime() > format: A character string. The default for the ‘format’ methods is > ‘"%Y-%m-%d %H:%M:%S"’ if any component has a time component > which is not midnight, and ‘"%Y-%m-%d"’ otherwise. If > ‘options("digits.secs")’ is set, up to the specified number > of digits will be printed for seconds. > > So, may be it is better to add a sec and later subtract it. > > dates.mine2<-dates.mine+1 > dates.mine2[3] > #[1] "2009-05-22 00:00:01 GMT" > dates.mine3<-dates.mine2-1 > dates.mine3[3] > #[1] "2009-05-22 GMT" > A.K. > > > > > > > - Original Message - > From: chuck.01 < > CharlieTheBrown77@ > > > To: > r-help@ > Cc: > Sent: Tuesday, October 30, 2012 5:21 PM > Subject: Re: [R] POSIXct date missing "time component" > > Um, OK. > My dates have times, they are 00:00:00 (i.e. midnight) > I'll just add a fraction of a second my dates and go with it. > > Thanks for the reply. > > > > > arun kirshna wrote >> HI, >> Please check this link >> (http://rss.acs.unt.edu/Rdoc/library/base/html/as.POSIXlt.html). >> "Dates without times are treated as being at midnight UTC. " >> >> May be you can try this (if it doesn't create additional problems): >> dates.mine2<-dates.mine+1 >> dates.mine2 >> #[1] "2009-05-21 23:30:01 GMT" "2009-05-21 23:45:01 GMT" >> #[3] "2009-05-22 00:00:01 GMT" "2009-05-22 00:15:01 GMT" >> dates.mine2[3] >> #[1] "2009-05-22 00:00:01 GMT" >> str(dates.mine2) >> #POSIXct[1:4], format: "2009-05-21 23:30:01" "2009-05-21 23:45:01" ... >> A.K. > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/POSIXct-date-missing-time-component-tp4647932p4647939.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@ > 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@ > 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. -- View this message in context: http://r.789695.n4.nabble.com/POSIXct-date-missing-time-component-tp4647932p4647963.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] grep txt file names from html
Sorry, I know I should read a little 1st about this, but I am actually just helping somebody really quick and need help too. I want to grep all of the names of the .txt files mentioned on this html web page: http://www.epa.gov/emap/remap/html/three/data/index.html Thanks ahead of time. -- View this message in context: http://r.789695.n4.nabble.com/grep-txt-file-names-from-html-tp4648037.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] extracting information from txt file
Hello, Here is a link to some data: http://www.epa.gov/emap/html/data/surfwatr/data/mastreams/9396/wchem/chmval.txt I am trying to read this in, and want to use: chmval <- read.table("http://www.epa.gov/emap/html/data/surfwatr/data/mastreams/9396/wchem/chmval.txt";, sep=",", skip= 84, header=T) the # 84, for 84 lines skipped needs to be derived from the 5th line of the txt file # Header Records: 85 so, I need that # (-1) for input into the read.table statement above I've tried grep but that didn't work: (for this I downloaded the txt file and manually removed that hash mark!) grep("Header Records:", read.table("chmval.txt", header=T)) Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1 did not have 5 elements Any ideas? Can I just extract the 5th line? -- View this message in context: http://r.789695.n4.nabble.com/extracting-information-from-txt-file-tp4648033.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] grep txt file names from html
Sorry Sarah. I want to store them as a vector for use later. so, similar to this: links <- c("http://www.epa.gov/emap/html/data/surfwatr/data/mastreams/9396/benthic/benmet.txt";, "http://www.epa.gov/emap/html/data/surfwatr/data/mastreams/9396/location/watchr.txt";, "http://www.epa.gov/emap/html/data/surfwatr/data/mastreams/9396/wchem/chmval.txt";) Sarah Goslee wrote > they're all of the form > > http.*txt > > but the best way to "grep" them (by which I assume you mean extract the > file names from the page source) depends on what you plan to do with them, > and what sort of output you expect. > > It isn't even clear whether you plan to do this in R. > > Sarah > > > On Wed, Oct 31, 2012 at 12:56 PM, chuck.01 < > CharlieTheBrown77@ > >wrote: > >> Sorry, I know I should read a little 1st about this, but I am actually >> just >> helping somebody really quick and need help too. >> >> I want to grep all of the names of the .txt files mentioned on this html >> web >> page: >> >> http://www.epa.gov/emap/remap/html/three/data/index.html >> >> Thanks ahead of time. >> >> > -- > Sarah Goslee > http://www.functionaldiversity.org > > [[alternative HTML version deleted]] > > __ > R-help@ > 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. -- View this message in context: http://r.789695.n4.nabble.com/grep-txt-file-names-from-html-tp4648037p4648043.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] Is there a way to export regression output to an excel spreadsheet?
Yes. see: ?lm ?coef ?write.csv also, if fit <- lm(Y~X) then: slope_p-value <- summary(fit)[[4]][2,4] Double check that last one for yourself. Good luck. hoguejm wrote > I want to export the coefficient values and p-values from my regression > output into a spreadsheet. Is there a way to do this? -- View this message in context: http://r.789695.n4.nabble.com/Is-there-a-way-to-export-regression-output-to-an-excel-spreadsheet-tp4649155p4649156.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] Random sampling many times and run through glm model
see: ?boot SASandRlearn wrote > I have a large dataset from which i need to take a random sample many > times ( say N=50) and run it through the same glm() - logistic regression > model everytime ( 50 times ) and capture the chi-square p-values ( Pr > > ChiSq ) of the variables for each run and output average p-value of the > variables that went into the model. > > I have done this in SAS. LIke to know how i can do this in R. Any help is > appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Random-sampling-many-times-and-run-through-glm-model-tp4649461p4649462.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] Jackknife in Logistic Regression
untested, but something like this should get you what you want: no.it <- 5 out <- vector("list", length=no.it) for(i in 1:no.it){ mydata2 <- mydata[ sample(1:nrow(mydata), 76000/no.it) ,] out[[i]] <- coef( glm(f_ocur~altitud+UTM_X+UTM_Y+j_sin+j_cos+temp_res+pp+offset(log(1/off)), data=mydata2, family='binomial') ) } do.call(c, out) Lucas wrote > Dear R friends > > I´m interested into apply a Jackknife analysis to in order to quantify the > uncertainty of my coefficients estimated by the logistic regression. I´m > using a glm(family=binomial) because my independent variable is in 0 - 1 > format. > > My dataset has 76000 obs, and I´m using 7 independent variables plus an > offset. The idea involves to split the data in lets say 5 random subsets > and then obtaining the 7 estimated parameters by dropping one subset at a > time from the dataset. Then I can estimate uncertainty of the parameters. > > I understand the procedure but I´m unable to do it in R. > > This is the model that I´m > fitting:*glm(f_ocur~altitud+UTM_X+UTM_Y+j_sin+j_cos+temp_res+pp+offset(log(1/off)), > data=mydata, family='binomial')* > > Does anyone have an idea of how can I make this possible? > > I´d really appreciate if someone could help me with this. > > Thank you in advance. > > P.S. More information can be added if needed. > > Best regards. > > Lucas. > > [[alternative HTML version deleted]] > > > __ > R-help@ > 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. -- View this message in context: http://r.789695.n4.nabble.com/Jackknife-in-Logistic-Regression-tp4649520p4649563.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] Biologist R learner
Please take the advice of Berend if you ever want to get help here. Also, you will need to do some basic and initial work yourself; read what he suggested, use Google to search keywords, and see great help like this: http://cran.r-project.org/doc/contrib/Short-refcard.pdf also, use the built in help pages by using a question mark like this: ?min ?max ?ifelse ?cumsum Good luck; don't let a sharp learning curve stop you from learning R. Anna23 wrote > I am a Biologist and a beginner, please help me to solve this: please > anyone..its my homework and I dont have a clue abt R yet.. >Write a function which does the following tasks: > > (a) Calculates minimum and maximum value of a given argument x. > (b) If x is positive, some new vector gets the value of TRUE, and FALSE > otherwise. > (c) Creates a vector where the i:th and (i-1):th values of x are always > summed. First value of > the new vector has the same value as the first component of x. Use the > created function to > some vector x to show that the function works. -- View this message in context: http://r.789695.n4.nabble.com/Biologist-R-learner-tp4650044p4650066.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] IMPORTANT!!!! PLEASE HELP ME
1st. Calm down, this doesn't seem that important. Then you will need to know some base functions. see ?rnorm Doing this 10,000 times and making them of size 50 is no problem. FYI: I don't understand what "with replacement case" means; could you clarify? Jasmin wrote > Hi, > I want to generate 1 samples from normal distribution with > replacement case and every sample size is 50. What should I do ? -- View this message in context: http://r.789695.n4.nabble.com/IMPORTANT-PLEASE-HELP-ME-tp4650676p4650677.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] How to count the number of different elements in a column
length(unique(a)) Hard Core wrote > Hello, > Suppose that i have a dataframe > a <- read.dta("banca_impresa.dta") > > i have a column with 17900 obs like > > 1 > 2 > 3 > 1 > 6 > 7 > 8 > 3 > 4 > 4 > > and i want to know the number of the different values so in this case it > would be 7 > How can i do? > Thank you -- View this message in context: http://r.789695.n4.nabble.com/How-to-count-the-number-of-different-elements-in-a-column-tp4650825p4650833.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] How to count the number of different elements in a column
My apologies. I still do not understand the difference; good luck. Hard Core wrote > this is wrong because with the command "unique" it counts the only values > that are unique .. > > in my column, for instance, 1 and 4 are not unique so the formula doesn't > work in my case -- View this message in context: http://r.789695.n4.nabble.com/How-to-count-the-number-of-different-elements-in-a-column-tp4650825p4650848.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] residuals from lm
FYI: As you are likely thinking: this doesn't belong here (It just occurred to me), I am questioning what I did, not the output of lm() But if someone knows why I am wrong please let me know. chuck.01 wrote > > Hi, > I was playing around with something else and I noticed this matrix code > for residuals in a linear model doesn't say what lm() says. Please tell > me if I am completely misguided here. > > data(mtcars) > Y <- as.matrix(mtcars[,1]) > X <- as.matrix(mtcars[,c(2:11)]) > > # shouldnt this: > H <- X %*% solve(t(X) %*% X) %*% t(X) > (diag(dim(H)[1]) - H) %*% Y > > # be equal to this: > residuals(lm(Y~X)) > > # ??? > # thanks > -- View this message in context: http://r.789695.n4.nabble.com/residuals-from-lm-tp4635155p4635161.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] residuals from lm
Hi, I was playing around with something else and I noticed this matrix code for residuals in a linear model doesn't say what lm() says. Please tell me if I am completely misguided here. data(mtcars) Y <- as.matrix(mtcars[,1]) X <- as.matrix(mtcars[,c(2:11)]) # shouldnt this: H <- X %*% solve(t(X) %*% X) %*% t(X) (diag(dim(H)[1]) - H) %*% Y # be equal to this: residuals(lm(Y~X)) # ??? # thanks -- View this message in context: http://r.789695.n4.nabble.com/residuals-from-lm-tp4635155.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] residuals from lm
nevermind... I forgot the column of 1's for the intercept term chuck.01 wrote > > Hi, > I was playing around with something else and I noticed this matrix code > for residuals in a linear model doesn't say what lm() says. Please tell > me if I am completely misguided here. > > data(mtcars) > Y <- as.matrix(mtcars[,1]) > X <- as.matrix(mtcars[,c(2:11)]) > > # shouldnt this: > H <- X %*% solve(t(X) %*% X) %*% t(X) > (diag(dim(H)[1]) - H) %*% Y > > # be equal to this: > residuals(lm(Y~X)) > > # ??? > # thanks > -- View this message in context: http://r.789695.n4.nabble.com/residuals-from-lm-tp4635155p4635183.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] Help with correlation matrices, thresholding
Try this as a starting point; dat is your whole data set, and r = correlation coefficient threshold: spec.cor <- function (dat, r, ...) { x <- cor(dat, ...) x[upper.tri(x, TRUE)] <- NA i <- which(abs(x) >= r, arr.ind = TRUE) data.frame(matrix(colnames(x)[as.vector(i)], ncol = 2), value = x[i]) } Drinniol wrote > > Hello, I am new to R and have a problem I have had some trouble with. > > Basically I have a list of some 8 genes or so with data points for > expression levels at various time points/conditions. I also have subsets > of these, usually only a few hundred genes in size, known to be associated > with some biological process. > > What I want to do is correlate the entire list with my subset and then > return out the gene names and correlations for correlations above a > certain threshold - the idea being that these would be good candidate > genes to look at more closely for possible interaction with said > biological process. > > What functions should I use to correlate the subset to the whole set - > keeping in mind that I need to keep track of gene names in both sets? And > how, then, from what I presume would be something like a 8 x 200 sized > matrix would I extract gene pair correlations over a certain threshold? > It would also probably be good if I could somehow remove the subset genes > from the whole gene list before computation so as to avoid useless 1 > correlations. > > I'll keep trying on my own, but any help would be appreciated! > -- View this message in context: http://r.789695.n4.nabble.com/Help-with-correlation-matrices-thresholding-tp4636697p4636704.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] nls help
Hello, I have data like the following: datum <- structure(list(Y = c(415.5, 3847.8325, 1942.83325, 1215.223, 950.142857325, 2399.585, 804.75, 579.5, 841.70825, 494.053571425 ), X = c(1.081818182, 0.492727273, 0.756363636, 0.896363636, 1.518181818, 0.49917, 1.354545455, 1.61, 1.706363636, 1.063636364 )), .Names = c("Y", "X"), row.names = c(NA, -10L), class = "data.frame") with(datum, plot(Y~X)) As you can see there is a non-linear association between X and Y, and I would like to fit an appropriate model. I was thinking an exponential decay model might work well. I tried the following (a and k starting values are based off of a lm() fit), but get an error. fit <- nls(Y ~ a*exp(-k * X), datum, start=c(a=3400, k=1867)) Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates I have never attempted to fit a non-linear model before, and thus the model may be inappropriately specified, or it is also possible that I have no idea what I am doing. Would someone please offer some advice. Thanks. Chuck -- View this message in context: http://r.789695.n4.nabble.com/nls-help-tp4123876p4123876.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] nls help
Ah, I see, thank you both. Michael Weylandt wrote > > It's a scaling problem: > > If you do this: > > datum <- datum[order(datum$X),] > > with(datum, plot(Y~X)) > with(datum, lines(X, 3400*exp(-1867*X))) > > you'll see that your initial guess is just so far gone that the nls() > optimizer can't handle it. > > If you try a more reasonable initial guess it works fine: > > fit <- nls(Y ~ a*exp(-k * X), datum, start=c(a=3400, k=1.867)) > > Michael > > On Wed, Nov 30, 2011 at 12:14 PM, chuck.01 <CharlieTheBrown77@> > wrote: >> Hello, >> I have data like the following: >> >> datum <- structure(list(Y = c(415.5, 3847.8325, 1942.83325, >> 1215.223, >> 950.142857325, 2399.585, 804.75, 579.5, 841.70825, 494.053571425 >> ), X = c(1.081818182, 0.492727273, 0.756363636, 0.896363636, >> 1.518181818, 0.49917, 1.354545455, 1.61, 1.706363636, 1.063636364 >> )), .Names = c("Y", "X"), row.names = c(NA, -10L), class = "data.frame") >> >> >> with(datum, plot(Y~X)) >> >> As you can see there is a non-linear association between X and Y, and I >> would like to fit an appropriate model. I was thinking an exponential >> decay >> model might work well. >> >> I tried the following (a and k starting values are based off of a lm() >> fit), >> but get an error. >> >> fit <- nls(Y ~ a*exp(-k * X), datum, start=c(a=3400, k=1867)) >> >> Error in nlsModel(formula, mf, start, wts) : >> singular gradient matrix at initial parameter estimates >> >> I have never attempted to fit a non-linear model before, and thus the >> model >> may be inappropriately specified, or it is also possible that I have no >> idea >> what I am doing. >> >> Would someone please offer some advice. >> >> Thanks. >> Chuck >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/nls-help-tp4123876p4123876.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@ 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@ 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. > -- View this message in context: http://r.789695.n4.nabble.com/nls-help-tp4123876p4124772.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] pasting several things
I have this type of format: structure(list(day = 19, C1 = structure(1L, .Label = c("", "C1" ), class = "factor"), C2 = structure(2L, .Label = c("", "C2"), class = "factor"), C3 = structure(1L, .Label = c("", "C3"), class = "factor"), Q1 = structure(2L, .Label = c("", "Q1"), class = "factor"), Q2 = structure(2L, .Label = c("", "Q2"), class = "factor"), Q3 = structure(1L, .Label = c("", "Q3"), class = "factor")), .Names = c("day", "C1", "C2", "C3", "Q1", "Q2", "Q3"), row.names = "8", class = "data.frame") > and want something like this: 19 -C2 _Q1_Q2 any ideas? obviously I could use paste() and get this. Keep in mind I have many of these and the presence of "C1", "C2", ... etc will vary. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/pasting-several-things-tp4439770p4439770.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] pasting several things
Hi Garrett, That works great, thank you! gsee wrote > > Try this: > > x <- structure(list(day = 19, C1 = structure(1L, .Label = c("", "C1" > ), class = "factor"), C2 = structure(2L, .Label = c("", "C2"), class = > "factor"), >C3 = structure(1L, .Label = c("", "C3"), class = "factor"), >Q1 = structure(2L, .Label = c("", "Q1"), class = "factor"), >Q2 = structure(2L, .Label = c("", "Q2"), class = "factor"), >Q3 = structure(1L, .Label = c("", "Q3"), class = "factor")), .Names = > c("day", > "C1", "C2", "C3", "Q1", "Q2", "Q3"), row.names = "8", class = > "data.frame") > > paste(x[1, 1], do.call(paste, c(x[1, x != ""][, -1], list(sep="_"))), > sep=" -") > > # Output looks like this >> paste(x[1, 1], do.call(paste, c(x[1, x != ""][, -1], list(sep="_"))), >> sep=" -") > [1] "19 -C2_Q1_Q2" >> x[1, 2] <- "C1" >> paste(x[1, 1], do.call(paste, c(x[1, x != ""][, -1], list(sep="_"))), >> sep=" -") > [1] "19 -C1_C2_Q1_Q2" > > HTH, > Garrett > > On Fri, Mar 2, 2012 at 2:39 PM, chuck.01 <CharlieTheBrown77@> wrote: >> I have this type of format: >> >> structure(list(day = 19, C1 = structure(1L, .Label = c("", "C1" >> ), class = "factor"), C2 = structure(2L, .Label = c("", "C2"), class = >> "factor"), >> C3 = structure(1L, .Label = c("", "C3"), class = "factor"), >> Q1 = structure(2L, .Label = c("", "Q1"), class = "factor"), >> Q2 = structure(2L, .Label = c("", "Q2"), class = "factor"), >> Q3 = structure(1L, .Label = c("", "Q3"), class = "factor")), .Names = >> c("day", >> "C1", "C2", "C3", "Q1", "Q2", "Q3"), row.names = "8", class = >> "data.frame") >>> >> >> and want something like this: >> >> 19 -C2 _Q1_Q2 >> >> any ideas? obviously I could use paste() and get this. Keep in mind I >> have >> many of these and the presence of "C1", "C2", ... etc will vary. >> >> >> Thanks. >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/pasting-several-things-tp4439770p4439770.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@ 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@ 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. > -- View this message in context: http://r.789695.n4.nabble.com/pasting-several-things-tp4439770p4441950.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] Correlation between 2 matrices but with subset of variables
Example data would be helpful A Ezhil wrote > > Dear All, > I have two matrices A (40 x 732) and B (40 x 1230) and would like to > calculate correlation between them. I can use: cor(A,B, method="pearson") > to calculate correlation between all possible pairs. But the issue is that > there is one-many specific mappings between A and B and I just need to > calculate correlations for those pairs (not all). Some variables in A > (proteins, say p1) have more than 3 (or 2 or 1) corresponding mapping in B > (mRNA, say, m1,m2,m3) and I would like calculate correlations between > p1-m1, p1-m2, and p1-m3 and then for the second variable p2 etc. > I have the mapping information in another file (annotation file). Could > you please suggest me how to do that? > Thanks in advance. > Kind regards,Ezhil > [[alternative HTML version deleted]] > > > __ > R-help@ 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. > -- View this message in context: http://r.789695.n4.nabble.com/Correlation-between-2-matrices-but-with-subset-of-variables-tp4458073p4458277.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] For loop and using its index
Hassan, Others have provided you with better solutions, but I hope this allows you to see why yours didn't work. # first (going with your code) you needed a data.frame called "x" # here is an example: x <- structure(list(x1 = c(0.0986048226696643, -0.445652024980979, 0.0893989676314604, -3.02656448303247, -0.966125836458264, -1.49916656636977, -1.43173455089552, 0.370528111260298, -1.16980816517156, -0.808744946153693 ), x2 = c(-0.765406771195136, -0.37933377428095, 1.38846324586498, -1.70043724374807, -0.71331175577977, 1.44597103991061, 1.31674350467787, -0.954578441470943, -1.30637013925954, 0.551870274117374), x3 = c(-0.122350075070145, 1.6217818199546, -0.824570718637696, -0.0341988842898353, 1.03924814479596, 0.898533448980663, 0.68074228601446, 0.296251937506574, -0.698501590358135, -0.0533564535030227)), .Names = c("x1", "x2", "x3"), row.names = c(NA, -10L), class = "data.frame") # you then need an empty vector to hold the results of your for loop (called "z" here) # note the square brackets as opposed to your parentheses z <- vector("list") for (i in 1:ncol(x)) { z[i] = 200 - x[i] } # finally, this will reassemble the output of the for loop z <- do.call(cbind, z) colnames(z) <- c("z1", "z2", "z3") # Finally, do read what the others sent you as they provide more efficient solutions HTH Chuck Hassan Eini Zinab wrote > > Dear All, > > I have a data set with variables x1, x2, x3, ..., x20 and I want to > create z1, z2, z3, ..., z20 with the following formula: > > > z1 = 200 - x1 > z2 = 200 - x2 > z3 = 200 - x3 > . > . > . > z20 = 200 - x20. > > > I tried using a for loop and its index as: > > for (i in 1:20) { > z(i) = 200 - x(i) > } > > But R gives the following error message: "Error: could not find function > "x"". > > Is there any other way for a simple coding of my 20 lines of code? > > Alohas, > Hassan Eini-Zinab > > __ > R-help@ 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. > -- View this message in context: http://r.789695.n4.nabble.com/For-loop-and-using-its-index-tp4459454p4460277.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] PCA in predefined Groups??
Without taking away all the fun of trial and error, and exploration in R... I will direct you to this website which I found invaluable when I first began to use R. one way would be to use: plot(Yourdata, type="n") and then 3 text() or points() statements to plot the groups represented by different colors. Good luck! SHAFI wrote > > Hi > > This has a simple answer but it has been eluding me nonetheless. > > I have been trying to build a PCA plot from scratch with the ability to > plot predefined groups in different colors. I can plot PCA but I want it > to plot with predefined groups(samples) with top 100 expressed genes. I > have three groups. Can any body help me keeping in mind that the user is > just beginner in R. > > Thanks in advance > -- View this message in context: http://r.789695.n4.nabble.com/PCA-in-predefined-Groups-tp4462536p4462765.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] How to convert factors to numbers
Using your posed data, the variable price was numeric: data.precios <- read.table("http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt";, header=T) str(data.precios) 'data.frame': 1996 obs. of 2 variables: $ time : int 37988 37991 37993 37994 37995 37998 37999 38000 38001 38002 ... $ price: num 18.1 26.1 30.9 34.7 27.6 ... HOWEVER! If I follow your code (eg. using " read.table(... , dec=",", sep="\t")": data.precios <- read.table("http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt";, header =TRUE , dec=",", sep="\t") > str(data.precios) 'data.frame': 1996 obs. of 2 variables: $ time : int 37988 37991 37993 37994 37995 37998 37999 38000 38001 38002 ... $ price: Factor w/ 1639 levels "10.80","12.53",..: 12 126 213 342 160 186 219 37 54 69 ... It is a factor but I can change it like this: > Price <- as.numeric(data.precios$price) > str(lPrice) num [1:1996] 12 126 213 342 160 186 219 37 54 69 ... I think avoiding it ever becoming a factor would be the better path. Good luck. sandro wrote > > Hello, I am relatively new to using R. > > The text file contains the date and price . I want to read and manipulate > the data in R. However, when I use read.table, it treats all of the data > as "factors" and I do not know how to treat the data as numbers: > > http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt p_diarios.txt > > setwd ("C:\\Users\\Sandro\\Dropbox\\R") > data.precios <- read.table ("p_diarios.txt ", header =TRUE > , dec=",", sep="\t") > Time <- data.precios$time # 01.02.2004 - 12.05.2011 > Price <- data.precios$price # Historical spot price > log.Price <- log(data.precios$price) > Error en Math.factor(c(12L, 126L, 213L, 342L, 160L, 186L, 219L, 37L, 54L, > : > log not meaningful for factors > > As you can see, I cannot calculate the price logarithms. > > Any help is appreciated. > > Sandro > -- View this message in context: http://r.789695.n4.nabble.com/How-to-convert-factors-to-numbers-tp4498828p4499019.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] show and produce PDF file with pdf() and dev.off( ) in function
1) thats not a function (i'm sure just a mistake) 2) Just add another plot line myplot <- function(x){ plot(x) pdf("xplot.pdf") plot(x) dev.off() } myplot(1:20) casperyc wrote > > Hi all, > > I know how to use pdf() and dev.off() to produce and save a graph. > > However, when I put them in a function say > > myplot(x=1:20){ > pdf("xplot.pdf") > plot(x) > dev.off() > } > > the function work. But is there a way show the graph in R as well as > saving it to the workspace? > > Thanks. > > casper > -- View this message in context: http://r.789695.n4.nabble.com/show-and-produce-PDF-file-with-pdf-and-dev-off-in-function-tp4500213p4500595.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] reading header in txt file and making histogram
dbh is the column name. What is the name of your data? Lets assume your data is called "YOUR_DATA" then try: with(YOUR_DATA, hist(dbh)) OR hist(YOUR_DATA$dbh) OR hist(YOUR_DATA[, "dbh"]) etc... bamboohydraulics wrote > > Dear all > > I am a BEGINNER and have R on my Mac. I saved my excel file as .txt file, > I have just one column with first row as the column name. My file when > read by R looks like this. After reading the table I try to make a > histogram by > hist(dbh), it says object dbh not found. What am I doing wrong? thanks > dbh > 1 11.53 > 2 16.05 > 37.36 > 4 16.05 > 58.66 > 6 12.74 > 7 22.93 > 87.55 > 95.10 > 10 21.34 > 11 0.32 > 12 9.71 > 13 0.00 > 14 15.92 > 15 11.85 > 16 14.43 > 17 4.59 > 18 14.43 > 19 7.99 > 20 2.61 > 21 23.69 > 22 6.05 > 23 9.87 > 24 4.90 > 25 3.18 > 26 3.82 > 27 0.00 > 28 12.10 > 29 5.22 > 30 6.37 > 31 6.50 > 32 10.83 > 33 3.63 > 34 2.93 > 35 3.60 > 36 5.89 > 37 3.63 > 38 2.55 > 39 2.96 > 40 3.69 > 41 5.57 > 42 0.00 > 43 7.07 > 44 5.48 > 45 9.55 > 46 3.44 > 47 0.00 > 48 0.00 > 49 3.69 > 50 2.48 > 51 3.38 > 52 2.64 > 53 12.10 > 54 3.34 > 55 0.00 > 56 4.52 > 57 6.59 > 58 9.65 > 59 9.01 > 60 12.93 > 61 0.00 > 62 4.24 > 63 9.75 > 64 4.39 > 65 2.90 > 66 6.85 > 67 9.08 > 68 5.54 > 69 6.02 > 70 7.64 > 71 6.85 > 72 0.00 > 73 3.12 > 74 6.75 > 75 4.24 > 76 2.32 > 77 2.58 > 78 2.55 > 79 8.60 > 80 0.00 > 81 0.32 > 82 2.23 > 83 3.98 > 84 6.05 > 85 7.64 > 86 3.03 > 87 0.00 > 88 9.27 > 89 0.00 > 90 0.00 > 91 3.92 > 92 0.00 > 93 20.54 > 94 8.41 > 95 0.00 > 96 2.10 > 97 0.00 > 98 0.00 > 99 13.79 > 100 5.22 > 101 9.43 > 102 6.31 > 103 4.11 > 104 0.00 > 105 0.00 > 106 6.15 > 107 3.41 > 108 14.01 > 109 15.67 > 110 17.20 > 111 20.00 > 112 11.43 > 113 10.35 > 114 10.29 > 115 13.18 > 116 10.61 > 117 0.00 > 118 0.32 > 119 0.00 > 120 7.01 > 121 1.97 > 122 4.52 > 123 19.14 > 124 3.50 > 125 2.99 > 126 3.18 > 127 1.82 > 128 3.18 > 129 6.02 > 130 4.04 > 131 2.61 > 132 2.48 > 133 2.71 > 134 2.68 > 135 1.82 > 136 2.52 > 137 6.72 > 138 2.61 > 139 2.74 > 140 3.15 > 141 3.25 > 142 3.22 > 143 3.44 > 144 4.01 > 145 4.97 > 146 6.15 > 147 9.62 > 148 2.87 > 149 5.83 > 150 17.90 > 151 3.18 > 152 3.54 > 153 2.99 > 154 4.62 > 155 6.85 > 156 0.00 > 157 5.83 > 158 4.49 > 159 2.74 > 160 6.82 > 161 6.82 > 162 4.94 > 163 5.83 > 164 6.02 > 165 0.96 > -- View this message in context: http://r.789695.n4.nabble.com/reading-header-in-txt-file-and-making-histogram-tp4504813p4504848.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] reading header in txt file and making histogram
You really need to read one of many beginners guides to R; but I will say this much: YOUR_DATA <- read.table("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt", header=TRUE) then you should be able to plot it like I said previously. If that still doesn't work, you need to read the posting guide and provide a lot more info than you have. At the very least, copy and paste the results of the following str(YOUR_DATA) bamboohydraulics wrote > > this is what I do, IT READS THE TABLE, But then I am stuck, I removed the > header > > read.table("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt", > header=FALSE) > hist("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt"$V1) > Error in "nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt"$V1 : > $ operator is invalid for atomic vectors > > or > > hist("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt",V1) > Error in hist.default("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt", > : > 'x' must be numeric > > or > with("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt",hist(V1)) > Error in eval(substitute(expr), data, enclos = parent.frame()) : > invalid 'envir' argument > -- View this message in context: http://r.789695.n4.nabble.com/reading-header-in-txt-file-and-making-histogram-tp4504813p4505919.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] What error distribution should I use?
Could you please post a small example of your data and code which gives you this error. Your assumed error distribution sounds reasonable. I am interested as to why you have zeros... you have sites with species richness ==0 ?? Lívia Dorneles Audino wrote > > I'm trying to make a glmm to identify the relationship between insect > species richness with fragment size, isolation and time (different years). > I already tried to analyse it using poisson distribution error, but I > always face with the following warning: > *glm.fit: fitted probabilities numerically 0 or 1 occurred * > > This is probably hapenning because my dataset has a lot of zeros. So, what > error distribution should I use? > > -- > *Lívia * > > [[alternative HTML version deleted]] > > > __ > R-help@ 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. > -- View this message in context: http://r.789695.n4.nabble.com/What-error-distribution-should-I-use-tp4509479p4510351.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] map and shapefile help
Hi, I want to use map("state") and have the ecoregion shape (please see link) file projected onto this. ftp://ftp.epa.gov/wed/ecoregions/cec_na/NA_CEC_Eco_Level3.zip ftp://ftp.epa.gov/wed/ecoregions/cec_na/NA_CEC_Eco_Level3.zip Could someone please show me how; I have never messed with this sort of thing. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/map-and-shapefile-help-tp4522794p4522794.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] map and shapefile help
Thanks you very much for your time Michael, and I have noted that this should have been asked at the R-Sig-Geo site cheers! Michael Sumner-2 wrote > > Sorry I take that back, I was using the (independent of GDAL) > shapefile reader in maptools. Using the rgdal package, we get the full > projection information from the auxiliary .xml file that ships with > the other shapefile files. > > library(rgdal) > > ## Here my working directory "." contains "NA_CEC_Eco_Level3.shp" > > x <- readOGR(".", "NA_CEC_Eco_Level3") > OGR data source with driver: ESRI Shapefile > Source: ".", layer: "NA_CEC_Eco_Level3" > with 2548 features and 11 fields > Feature type: wkbPolygon with 2 dimensions > > > summary(x) > Object of class SpatialPolygonsDataFrame > Coordinates: >min max > x -4334052 3324076 > y -3313739 4267265 > Is projected: TRUE > proj4string : > [+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 > +units=m +no_defs] > Data attributes: >NA_L3CODE > ... > > So, now we can do this: > > library(maps) > require(rgdal) > > map("state", col = "aliceblue", fill = TRUE, lwd = 2) > plot(spTransform(x, CRS("+proj=longlat +ellps=WGS84")), add = TRUE) > > (Clearly I should have taken this to R-Sig-Geo some time ago). > > Cheers, Mike. > > > On Sun, Apr 1, 2012 at 6:09 PM, Michael Sumner <mdsumner@> wrote: >> There is no coordinate system defined for these files- proj4string is >> NA, see below - otherwise transforming them to that used by the maps >> package is trivial. I suggest you find out the coordinate system from >> the provider of the data and ask any further questions on R-Sig-Geo. >> This is a big file, ~34 Mb and you should warn people of that. >> >> library(maptools) >> x <- readShapeSpatial("NA_CEC_Eco_Level3.shp") >> >> summary(x) >> Object of class SpatialPolygonsDataFrame >> Coordinates: >> min max >> x -4334052 3324076 >> y -3313739 4267265 >> Is projected: NA >> proj4string : [NA] >> Data attributes: >> NA_L3CODE NA_L3NAME >> 8.5.2 : 217 Mississippi Alluvial Plain : 217 >> 7.1.5 : 208 Coastal Western Hemlock-Sitka Spruce Forests: 208 >> 8.5.1 : 163 Middle Atlantic Coastal Plain : 163 >> 8.5.3 : 147 Southern Coastal Plain : 147 >> 2.1.5 : 135 Foxe Uplands : 135 >> 8.1.8 : 98 Acadian Plains and Hills : 98 >> (Other):1580 (Other) :1580 >> ... >> >> >> >> On Sun, Apr 1, 2012 at 4:55 PM, Michael Sumner <mdsumner@> wrote: >>> Try the R-Sig-Geo mailing list for a better target community, but if >>> these >>> are shapefiles there is read support in rgdal (or maptools for a simpler >>> alternative) and if these are in long-lat like the maps package then >>> plot(x, >>> add=TRUE) will be most of the way there. >>> >>> If you need to transform either layer then see spTransform or project in >>> rgdal. >>> >>> Cheers, Mike >>> >>> >>> On Sunday, April 1, 2012, chuck.01 wrote: >>>> >>>> Hi, >>>> I want to use map("state") and have the ecoregion shape (please see >>>> link) >>>> file projected onto this. >>>> >>>> ftp://ftp.epa.gov/wed/ecoregions/cec_na/NA_CEC_Eco_Level3.zip >>>> ftp://ftp.epa.gov/wed/ecoregions/cec_na/NA_CEC_Eco_Level3.zip >>>> >>>> Could someone please show me how; I have never messed with this sort of >>>> thing. >>>> Thanks. >>>> >>>> -- >>>> View this message in context: >>>> http://r.789695.n4.nabble.com/map-and-shapefile-help-tp4522794p4522794.html >>>> Sent from the R help mailing list archive at Nabble.com. >>>> >>>> __ >>>> R-help@ 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. >>> >>> >>> >>> -- >>> Michael Sumner >>> Institute for Marine and Antarctic Studies, University of Tasmania >>> Hobart, Australi
Re: [R] Function - simple question
This is one way: f <- function(x, y){ Z <- ifelse(x==y, 3, 4) return(Z) } DS[3] <- with(DS, f(X,Y)) colnames(DS)[3] <- "Z" But you don't really need a function to do that. DS[3] <- with(DS, ifelse(X==Y, 3, 4)) # this works just fine I'm glad you've decided to use R; eventually you will need to read some intro R manuals. Cheers. flacerdams wrote > > Dear all, > > Suppose I have a dataset with two variables: > > X = c(0, 1, 2) > Y = c(1, 1, 1) > DS = data.frame(X, Y) > > Now, I want to create a new variable Z with 3 observations, but I want its > values to be the result of a function. I want to create a function that > compares X and Y, and if X = Y, then Z value = 3. If X value differs from > Y value, Z value = 4. So, I'd have the following values for Z: 4, 3, 4. > > How can I create a function like that? (Sorry, I know it's a dumb > question, I began to use R two days ago) > > Thank you very much, > > Lacerda > -- View this message in context: http://r.789695.n4.nabble.com/Function-simple-question-tp4536162p4536189.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] Grabbing Column and Row titles
Please use dput() to post your example matrix. Rambler1 wrote > > I have run into a problem in my code. What I want to accomplish is this: > I have a user input stock symbols into a list and from there I run the > quantmod package to get historical data. I compute the correlation matrix > and then turn that matrix into a simple matrix with 1's or 0's depending > on how strong the correlation is. From here I would like to go into the > matrix and take all the 1's and match them with their row/column titles. > So for each 1 I have two stock symblos. For example: > MMM ACE ABT ANF HD PEP K GOOG BIDU JNJ > MMM 01 0 0 0 1 0 0 0 > 0 > ACE 10 0 0 0 0 0 0 > 0 1 > ABT 00 0 0 0 1 0 0 > 0 1 > ANF 00 0 0 0 0 00 > 0 0 > HD 00 0 0 0 0 00 > 0 0 > PEP 10 1 0 0 0 00 > 0 1 > K 00 0 0 0 0 0 0 > 0 0 > GOOG 00 0 0 0 0 0 0 0 > 0 > BIDU00 0 0 0 0 0 0 > 0 0 > JNJ 0 1 1 0 0 1 0 0 > 0 0 > > Say I have this matrix computed. I would like to locate every 1 and the > corresponding two names that go with it. (eg MMM/ACE, MMM/PEP and so on.) > Thank you for your help! > -- View this message in context: http://r.789695.n4.nabble.com/Grabbing-Column-and-Row-titles-tp4332136p4333698.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] Grabbing Column and Row titles
This is true with regard to all things you don't understand in R... use question mark (?) # this will show you the manual, or help page ?dput also, make sure you hit the "quote" button when you reply on this forum so that people know what you are replying to. I used dput() to create the following (see previous post): x <- structure(list(a = c(0L, 1L, 0L), b = c(1L, 0L, 1L), c = c(0L, 1L, 0L)), .Names = c("a", "b", "c"), class = "data.frame", row.names = c("a", "b", "c")) now see what "x" is: > x a b c a 0 1 0 b 1 0 1 c 0 1 0 now use dput(): > dput(x) structure(list(a = c(0L, 1L, 0L), b = c(1L, 0L, 1L), c = c(0L, 1L, 0L)), .Names = c("a", "b", "c"), class = "data.frame", row.names = c("a", "b", "c")) Now if you paste this in your post, people can easily "play" around with your data and try to help. Good luck with your endeavors. Rambler1 wrote > > Thank you very much I will try this and see how it goes. Also what do you > mean by using dput() to post? I'm new to the blog. Than you again. > -- View this message in context: http://r.789695.n4.nabble.com/Grabbing-Column-and-Row-titles-tp4332136p4334377.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] Grabbing Column and Row titles
I would suggest reading some introductory manuals on R; specifically (with regards to your question) how to construct a function. Basically, "dat" is a variable input to the function. Everywhere you see "dat" is replaced by whatever you put in; for example: f(x) puts the data.frame "x" in for "dat" throughout the function. If you plan of expanding this function, I think you need to read a little bit first (perhaps a lot actually) so you know the basic mechanics. happy reading. Rambler1 wrote > > in this code: > > f <- function(dat, ...) { > dat[upper.tri(dat, TRUE)] <- NA > i <- which(dat == 1, arr.ind = TRUE) > data.frame(matrix(colnames(dat)[as.vector(i)], ncol = 2)) > } > > I am planning to make this part of a larger function is there anyway I can > extract the code without the "function(dat,...){}" and have it run in a > larger function? > Also what is the context of the command "dat" R is very new and confusing > to me and sometimes ?# doesn't fully explain it for me. Thank you! > > > > chuck.01 wrote >> >> This is true with regard to all things you don't understand in R... use >> question mark (?) # this will show you the manual, or help page >> >> ?dput >> >> also, make sure you hit the "quote" button when you reply on this forum >> so that people know what you are replying to. >> >> I used dput() to create the following (see previous post): >> >> x <- structure(list(a = c(0L, 1L, 0L), b = c(1L, 0L, 1L), c = c(0L, >> 1L, 0L)), .Names = c("a", "b", "c"), class = "data.frame", row.names = >> c("a", >> "b", "c")) >> >> now see what "x" is: >> >>> x >> a b c >> a 0 1 0 >> b 1 0 1 >> c 0 1 0 >> >> >> now use dput(): >> >>> dput(x) >> structure(list(a = c(0L, 1L, 0L), b = c(1L, 0L, 1L), c = c(0L, >> 1L, 0L)), .Names = c("a", "b", "c"), class = "data.frame", row.names = >> c("a", >> "b", "c")) >> >> Now if you paste this in your post, people can easily "play" around with >> your data and try to help. >> >> Good luck with your endeavors. >> >> >> >> >> Rambler1 wrote >>> >>> Thank you very much I will try this and see how it goes. Also what do >>> you mean by using dput() to post? I'm new to the blog. Than you again. >>> >> > -- View this message in context: http://r.789695.n4.nabble.com/Grabbing-Column-and-Row-titles-tp4332136p4334714.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] Graph Titles
Hard to help without a short example dataset (please read posting guide!) posted with dput(). You likely want to "paste" together a title for your graph. see ?paste Rambler1 wrote > > Another simple question that is driving me crazy: > I have a for loop that loops through a matrix and pulls data from two > different variables, computes differences and runs a regression then plots > a formula I made: > > for(i in 1:1){ > halo <- sex[i,] > holder <- get(halo)['2011::'][,6] > halo2 <- sex[i,2] > holder2 <- get(halo2)['2011::'][,6] > ret1<- diff(holder)[-1] > ret2<- diff(holder2)[-1] > model<- lm(ret1 ~ ret2 - 1) > hr <- as.numeric(model$coefficients[1]) > pairs <- ret1 - hr * ret2 > plot(pairs) > } > > The loop works fine and the appropriate number of graphs are printed. > > How would I go about putting a title at the top that would change for each > graph? > That two variables are "halo" and "halo2" form the for loop. > > Ideally I want it to look like this: > plot(pairs, main = halo " vs " halo2) > > Thank you for your help. > -- View this message in context: http://r.789695.n4.nabble.com/Graph-Titles-tp4335020p4336830.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] Contour plot with messy field data.
Hello, I have some data that will be in the form: structure(list(station = structure(c(20L, 2L, 4L, 19L, 3L, 11L, 1L, 5L, 10L, 12L, 17L, 18L, 6L, 9L, 13L, 16L, 7L, 8L, 15L, 14L ), .Label = c("1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "2", "3", "4", "5", "6", "7", "8", "9", "scope" ), class = "factor"), distance = c(0, 2, 0.8, 3, 1.2, 1.7, 1, 1.4, 2.8, 2.2, 4.5, 4.2, 2.8, 3.6, 3.4, 4.8, 3.8, 4.2, 4.8, 4.4 ), degrees = c(0, 90, 89.9, 82.4, -59, 69.4, 10.8, 45, 69, 26.6, 63.4, 61.6, 45, 56.3, 28.1, 51.7, 38.7, 45, 38.3, 25.4), z = c(0L, 0L, -1L, 0L, 0L, -1L, 0L, -1L, -1L, 0L, 0L, 0L, -1L, -1L, 0L, 0L, -1L, -1L, 0L, 0L), x = c(0, 0, 0, 0.4, 0.6, 0.6, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3.8, 4), y = c(0, 2, 0.8, 3, -1, 1.6, 0.19, 1, 2.6, 1, 4, 3.7, 2, 3, 1.6, 3.8, 2.4, 3, 3, 1.9)), .Names = c("station", "distance", "degrees", "z", "x", "y"), row.names = c(1L, 11L, 13L, 10L, 12L, 20L, 2L, 14L, 19L, 3L, 8L, 9L, 15L, 18L, 4L, 7L, 16L, 17L, 6L, 5L), class = "data.frame") Basically, I would like to create a contour plot and eventually be able to calculate the % area within each contour. This only has 2 contour lines of height z=0, and z=-1. I would like to have as many and these z values likely won't fall nicely into a contour with others. This may give you an idea of the spatial arrangement of observations. http://r.789695.n4.nabble.com/file/n4353603/Slide1.png Does anyone have any suggestions on how to begin doing this? -- View this message in context: http://r.789695.n4.nabble.com/Contour-plot-with-messy-field-data-tp4353603p4353603.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] Contour plot with messy field data.
Ok, I've since found this: # called previously posted dataset "dat" attach(dat) library(akima) data.interp <- interp(x,y,z) contour(data.interp) any idea how to calculate area within specified contour lines? Thanks chuck.01 wrote > > Hello, > I have some data that will be in the form: > > structure(list(station = structure(c(3L, 20L, 2L, 4L, 19L, 11L, > 1L, 5L, 10L, 12L, 17L, 18L, 6L, 9L, 13L, 16L, 7L, 8L, 15L, 14L > ), .Label = c("1", "10", "11", "12", "13", "14", "15", "16", > "17", "18", "19", "2", "3", "4", "5", "6", "7", "8", "9", "scope" > ), class = "factor"), distance = c(1.2, 0, 2, 0.8, 3, 1.7, 1, > 1.4, 2.8, 2.2, 4.5, 4.2, 2.8, 3.6, 3.4, 4.8, 3.8, 4.2, 4.8, 4.4 > ), degrees = c(-59, 0, 90, 89.9, 82.4, 69.4, 10.8, 45, 69, 26.6, > 63.4, 61.6, 45, 56.3, 28.1, 51.7, 38.7, 45, 38.3, 25.4), z = c(0L, > 0L, 0L, -1L, 0L, -1L, 0L, -1L, -1L, 0L, 0L, 0L, -1L, -1L, 0L, > 0L, -1L, -1L, 0L, 0L), x = c(-0.6, 0, 0, 0, 0.4, 0.6, 1, 1, 1, > 2, 2, 2, 2, 2, 3, 3, 3, 3, 3.8, 4), y = c(1, 0, 2, 0.8, 3, 1.6, > 0.19, 1, 2.6, 1, 4, 3.7, 2, 3, 1.6, 3.8, 2.4, 3, 3, 1.9)), .Names = > c("station", > "distance", "degrees", "z", "x", "y"), row.names = c(12L, 1L, > 11L, 13L, 10L, 20L, 2L, 14L, 19L, 3L, 8L, 9L, 15L, 18L, 4L, 7L, > 16L, 17L, 6L, 5L), class = "data.frame") > > > I would like to create a contour plot and eventually be able to calculate > the % area within each contour. > This only has 2 contour lines of height z=0, and z=-1; I would like to > have as many and these z values likely won't fall nicely into a contour > with others. Also, linear interpolation adding at least one point between > observed points would be great. > > This may give you an idea of the spatial arrangement of observations. > http://r.789695.n4.nabble.com/file/n4353603/Slide1.png > > Does anyone have any suggestions on how to begin doing this? > -- View this message in context: http://r.789695.n4.nabble.com/Contour-plot-with-messy-field-data-tp4353603p4353662.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] Contour plot with messy field data.
This is ugly, but I think it works.: z.2 <- data.frame(data.interp[[3]]) diff_y <- unique(round(diff(data.interp[[2]]), 4)) diff_x <- unique(round(diff(data.interp[[1]]), 4)) total_area <- length(which(z.2!="NA"))*diff_y*diff_x # percent of total area less than -.5 (as I wanted) Per_neg_0.5 <- (length(which(z.2<=-.5))*diff_y*diff_x)/total_area If you see a problem, please let me know. chuck.01 wrote > > Ok, > I've since found this: > > # called previously posted dataset "dat" > > attach(dat) > library(akima) > data.interp <- interp(x,y,z) > contour(data.interp) > > > any idea how to calculate area within specified contour lines? > > Thanks > > > > > chuck.01 wrote >> >> Hello, >> I have some data that will be in the form: >> >> structure(list(station = structure(c(3L, 20L, 2L, 4L, 19L, 11L, >> 1L, 5L, 10L, 12L, 17L, 18L, 6L, 9L, 13L, 16L, 7L, 8L, 15L, 14L >> ), .Label = c("1", "10", "11", "12", "13", "14", "15", "16", >> "17", "18", "19", "2", "3", "4", "5", "6", "7", "8", "9", "scope" >> ), class = "factor"), distance = c(1.2, 0, 2, 0.8, 3, 1.7, 1, >> 1.4, 2.8, 2.2, 4.5, 4.2, 2.8, 3.6, 3.4, 4.8, 3.8, 4.2, 4.8, 4.4 >> ), degrees = c(-59, 0, 90, 89.9, 82.4, 69.4, 10.8, 45, 69, 26.6, >> 63.4, 61.6, 45, 56.3, 28.1, 51.7, 38.7, 45, 38.3, 25.4), z = c(0L, >> 0L, 0L, -1L, 0L, -1L, 0L, -1L, -1L, 0L, 0L, 0L, -1L, -1L, 0L, >> 0L, -1L, -1L, 0L, 0L), x = c(-0.6, 0, 0, 0, 0.4, 0.6, 1, 1, 1, >> 2, 2, 2, 2, 2, 3, 3, 3, 3, 3.8, 4), y = c(1, 0, 2, 0.8, 3, 1.6, >> 0.19, 1, 2.6, 1, 4, 3.7, 2, 3, 1.6, 3.8, 2.4, 3, 3, 1.9)), .Names = >> c("station", >> "distance", "degrees", "z", "x", "y"), row.names = c(12L, 1L, >> 11L, 13L, 10L, 20L, 2L, 14L, 19L, 3L, 8L, 9L, 15L, 18L, 4L, 7L, >> 16L, 17L, 6L, 5L), class = "data.frame") >> >> >> I would like to create a contour plot and eventually be able to calculate >> the % area within each contour. >> This only has 2 contour lines of height z=0, and z=-1; I would like to >> have as many and these z values likely won't fall nicely into a contour >> with others. Also, linear interpolation adding at least one point >> between observed points would be great. >> >> This may give you an idea of the spatial arrangement of observations. >> http://r.789695.n4.nabble.com/file/n4353603/Slide1.png >> >> Does anyone have any suggestions on how to begin doing this? >> > -- View this message in context: http://r.789695.n4.nabble.com/Contour-plot-with-messy-field-data-tp4353603p4353754.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] Binding matrices of different sizes
http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=search_page&node=789695&query=cbind+with+different+rows Rambler1 wrote > > I am trying to bind two matrices of different length. They both are one > column and many rows but the rows differ by a few. How am I able to cbind > them together inserting NA's to fill the missing rows and make them the > same length? Thanks in advance for any help! > -- View this message in context: http://r.789695.n4.nabble.com/Binding-matrices-of-different-sizes-tp4356060p4356349.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] How to Compare the median to the mean?
I found something a little different: > median(nb10[,1]) [1] 404 > mean(nb10[,1]) [1] 404.59 compare them They are different. Your sample is not perfectly symmetrical (50% above, 50% below) about the mean (ie. the third standardized moment (skewness) is not zero). This is really not a question about R, and this is not a place to get answers for homework. Good luck with your studies. Ajata Paul wrote > > Okay, so I have a homework projecr for R, and we had to input the > following link as some sort of data: > nb10 <- read.table("http://www.adjoint-functors.net/su/web/314/R/NB10";). > Afterwards, we have to use > fivenum(nb10) to find max, min, quantiles, and sd, but I'm okay with this. > The next question is where I'm stuck. The question is as follows; > Compare the median (use the quantiles or median(nb10$V1)) to the mean. I > found the mean to be 408.8 and the median to be 404. Can you please > explain to me what I need to put into the program to get an answer and > explain what the answer means? > > Thank You. > -- View this message in context: http://r.789695.n4.nabble.com/How-to-Compare-the-median-to-the-mean-tp4357520p4357544.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] 3d average values
Hello, given the set of grey points (corners of squares, see visual)... something like this: http://r.789695.n4.nabble.com/file/n4363505/Slide2.png how do I calculate the average value of the variable z, that was measured at the corners of the rectangles (represented by the black points in the picture above). #here is some data (dat) dat <- structure(list(z = c(0L, 0L, 0L, -1L, 0L, -1L, 0L, -1L, -1L, + 0L, 0L, 0L, -1L, -1L, 0L, 0L, -1L, -1L, 0L, 0L), x = c(-0.6, + 0, 0, 0, 0.4, 0.6, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3.8, 4 + ), y = c(1, 0, 2, 0.8, 3, 1.6, 0.19, 1, 2.6, 1, 4, 3.7, 2, 3, + 1.6, 3.8, 2.4, 3, 3, 1.9)), .Names = c("z", "x", "y"), class = "data.frame", row.names = c(12L, + 1L, 11L, 13L, 10L, 20L, 2L, 14L, 19L, 3L, 8L, 9L, 15L, 18L, 4L, + 7L, 16L, 17L, 6L, 5L)) attach(dat) library(akima) # interpolating to square grid data.interp <- interp(x,y,z) I would like the "black dots" (rectangle corner averages) from data.interp[z] anybody know how? -- View this message in context: http://r.789695.n4.nabble.com/3d-average-values-tp4363505p4363505.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] Reading in csv with footer
I believe this should work d <- read.table("foo.csv", header=T, sep=",", comment="T") although its spitting back a warning... this used to work for me. Noah Silverman wrote > > Hi, > > I have a CSV file that is formatted well, except that the last line is a > "summary" not is CSV format. > > Toy example: > > label_1, label_2, label_3 > 1,2,3 > 3,2,4 > 2,3,4 > Total Rows: 3 > > > When I try to import this into R with: d <- read.table("foo.csv", > header=T, sep=",") > It fails to import properly because of the last line. > > Currently, I have a shell script that strips the last line from the file, > then it imports to R cleanly. I don't like this extra layer of > processing. > > Is there a way to import something like this cleanly in R. > > Thanks! > > -- > Noah > __ > R-help@ 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. > -- View this message in context: http://r.789695.n4.nabble.com/Reading-in-csv-with-footer-tp4382441p4382980.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] comparing vectors with condition
sum(ifelse(x*total!=0, as.numeric(x> total), 0)) arunkumar wrote > > Hi > > I have two vector > > x=c(10,30,40,50) > total=c(20,20,0,10) > > Var_exceeding_total=sum(as.numeric(x> total)) > > This will compare the vectors x and total a gives the result. > > if i want to compare only if the y > 0 . > can we apply condition in the comparison ? > -- View this message in context: http://r.789695.n4.nabble.com/comparing-vectors-with-condition-tp4382946p4383000.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] matching a sequence in a vector?
this is ugly, but... l <-length(patrn) l2 <-length(exmpl) out <- vector("list") for(i in 1:(l2-l+1)) { exmpl[i:(i+l-1)] patrn==exmpl[i:(i+l-1)] if(all(patrn==exmpl[i:(i+l-1)])) { out[[i]] <- i } else { out[[i]] <- "NA"} } out <- do.call(c, out) as.numeric(out[which(out!="NA")]) ## Cheers and HTH Redding, Matthew-2 wrote > > Hi All, > > > I've been trawling through the documentation and listserv archives on this > topic -- but > as yet have not found a solution. I'm sure this is pretty simple with R, > but I cannot work out how without > resorting to ugly nested loops. > > As far as I can tell, grep, match, and %in% are not the correct tools. > > Question: > given these vectors -- > patrn <- c(1,2,3,4) > exmpl <- c(3,3,4,2,3,1,2,3,4,8,8,23,1,2,3,4,4,34,4,3,2,1,1,2,3,4) > > how do I get the desired answer by finding the occurence of the pattern > and returning the starting indices: > 6, 13, 23 > > Suggestions very much appreciated! > > Kind regards, > > > > > Matt Redding, Ph.D. > Principal Scientist > Geochemist/Soil Chemist > Queensland Primary Industries & Fisheries > DEEDI > PO Box 102, Toowoomba, 4350, Qld > ph: 0746 881372 > fax: 0746 881192 > > > DISCLAIMER**...{{dropped:15}} > > __ > R-help@ 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. > -- View this message in context: http://r.789695.n4.nabble.com/matching-a-sequence-in-a-vector-tp4389523p4389560.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] incomplete final line found by readTableHeader on 'test.csv'
Hello, I have recently had issues with read.csv where i get the following warning, and this happens on both my OSX and Linux machines. Here is the warning and an example CSV file is attached: Warning message: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'test.csv' http:// http://r.789695.n4.nabble.com/file/n4396383/test.csv test.csv I don't quite understand. Any thoughts are appreciated. -- View this message in context: http://r.789695.n4.nabble.com/incomplete-final-line-found-by-readTableHeader-on-test-csv-tp4396383p4396383.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] How to resample matrices to test for the robustness of their correlation
see: ?sample library(vegan) ?rrarefy not knowing your data structure, its hard to say. camilleislande wrote > > Hello > I have several populations where I have morphology and diet for each > individual. I am interested in the correlation between diet and > morphological distances. However the number of individuals in each > population ranges from 22 to 80 individuals. I have looked at the > correlation diet-morphology for each population and (not surprisingly) the > correlation coefficientis is highly correlated with the number of > individuals per population. > > I would like to resample (without replacement) the populations with 60-80 > individuals and get random samplings of 30 individuals (1000 times). I > would like to get a correlation coefficient distribution against which to > test the original value of the correlation. > > I guess it is possible do this, however I have never written a script in R > and I am not familiar with resampling techniques at all. Any help with > coding will be greatly appreciated > > Thank you > -- View this message in context: http://r.789695.n4.nabble.com/How-to-resample-matrices-to-test-for-the-robustness-of-their-correlation-tp4397915p4399189.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] loop for a large database
Untested die to no data, but this should work with a loop out=vector("list", length= length(MyVector)) for(i in 1 : length (MyVector)) { x <- data.frame (sum (MyTable ==MyVector[i])) out[[i]] <- x } sum(do.call(rbind, out)) -- View this message in context: http://r.789695.n4.nabble.com/loop-for-a-large-database-tp4422052p4422584.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] call object from character?
Let say I have an object (I hope my terminology is correct) a a <- 12 > a [1] 12 And "a" has been assigned the number 12, or whatever And lets say I have a character "call_A" call_A <- "a" >call_A [1] "a" What is the function "F" that allows this to happen: > F( call_A ) [1] 12 -- View this message in context: http://r.789695.n4.nabble.com/call-object-from-character-tp4569686p4569686.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] call object from character?
I figured as much. Thank you greatly. plangfelder wrote > > On Wed, Apr 18, 2012 at 7:25 PM, chuck.01 <CharlieTheBrown77@> > wrote: >> Let say I have an object (I hope my terminology is correct) a >> a <- 12 >>> a >> [1] 12 >> >> And "a" has been assigned the number 12, or whatever >> And lets say I have a character "call_A" >> call_A <- "a" >>>call_A >> [1] "a" >> >> What is the function "F" that allows this to happen: >>> F( call_A ) >> [1] 12 > > > Use get: > >> a = 12 >> get("a") > [1] 12 > > HTH, > > Peter > > __ > R-help@ 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. > -- View this message in context: http://r.789695.n4.nabble.com/call-object-from-character-tp4569686p4569801.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] fill a dataframe with zeros where the rows are a smaller subset of a larger dataframe (species by site)
-- View this message in context: http://r.789695.n4.nabble.com/fill-a-dataframe-with-zeros-where-the-rows-are-a-smaller-subset-of-a-larger-dataframe-species-by-sit-tp4586534p4586711.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] Merge function - Return NON matches
# dput() example # lets say you have data called y, like this: > y sp1 sp2 sp3 sp4 d 0 0 0 0 e 0 0 0 0 f 0 0 0 0 # ok, so do this: > dput(y) structure(list(sp1 = c(0, 0, 0), sp2 = c(0, 0, 0), sp3 = c(0, 0, 0), sp4 = c(0, 0, 0)), .Names = c("sp1", "sp2", "sp3", "sp4" ), row.names = c("d", "e", "f"), class = "data.frame") # now copy and paste that into your R terminal to see why it is so nice. RHelpPlease wrote > > Hi there, > Thanks for your responses. I haven't used/heard of dput() before. I'm > looking it up & understanding how it works. > > Thanks! > -- View this message in context: http://r.789695.n4.nabble.com/Merge-function-Return-NON-matches-tp4590755p4591189.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] problem with get() inside of lme()
Hi, In the following lines of code are inside of a function, where "TRAIT1" is a function variable calling a column-name inside of the data.frame "new3". This works just fine: m2 <- lmer(get(TRAIT1) ~ perm.score + (1|site), data=new3) but this will not work, m3 <- lme(get(TRAIT1) ~ perm.score , random= ~1|site, data=new3) I get the following error: Error in model.frame.default(formula = ~TRAIT1 + perm.score + site, data = list( : variable lengths differ (found for 'perm.score') it seems to be putting TRAIT1 on the left side of the equation, and if I am wong about that, this is still not true: length(with(new3, perm.score))==length(with(new3, get(TRAIT1))) Any ideas on either what is going on, or how I can fix this? ** I'm not including example data, or function because I am hoping it is not needed ** Please let me know if I am wrong. -- View this message in context: http://r.789695.n4.nabble.com/problem-with-get-inside-of-lme-tp4629360.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] problem with get() inside of lme()
please note that I edited the original message to say: > length(with(new3, perm.score))==length(with(new3, get(TRAIT1))) [1] TRUE chuck.01 wrote > > Hi, > The following lines of code are inside of a function, where "TRAIT1" is > a function variable calling a column-name inside of the data.frame "new3". > > This works just fine: > > m2 <- lmer(get(TRAIT1) ~ perm.score + (1|site), data=new3) > > but this will not work: > > m3 <- lme(get(TRAIT1) ~ perm.score , random= ~1|site, data=new3) > > I get the following error: > > Error in model.frame.default(formula = ~TRAIT1 + perm.score + site, data = > list( : > variable lengths differ (found for 'perm.score') > > it seems to be putting TRAIT1 on the left side of the equation, and if I > am wrong about that, the different lengths from the error is still not > true: > >> length(with(new3, perm.score))==length(with(new3, get(TRAIT1))) > [1] TRUE > > Any ideas on either what is going on, or how I can fix this? > > ** I'm not including example data, or function because I am hoping it is > not needed ** > Please let me know if I am wrong. > -- View this message in context: http://r.789695.n4.nabble.com/problem-with-get-inside-of-lme-tp4629360p4629417.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] round up/down to nearest hundredth
Hi, How can I round up and down to the nearest hundredth example: x <- 0.18 how do I round down to 0.15? how do I round down to 0.20? -- View this message in context: http://r.789695.n4.nabble.com/round-up-down-to-nearest-hundredth-tp4629451.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] problem with get() inside of lme()
Here is an example: library(nlme) library(lme4) library(MASS) data(petrol) # a variable for one of the columns in petrol Y.VAR <- "Y" # This works: lmer(get(Y.VAR)~EP +(1|No), data=petrol) # This doesn't: lme(get(Y.VAR)~EP, random= ~1|No, data=petrol) # but this does: lme(Y~EP, random= ~1|No, data=petrol) I'd really like to use the variable... again, this is inside a function. Any idea how to solve this. Thanks for your time and expertise, Chuck chuck.01 wrote > > please note that I edited the original message to say: > >> length(with(new3, perm.score))==length(with(new3, get(TRAIT1))) > [1] TRUE > > > > > > chuck.01 wrote >> >> Hi, >> The following lines of code are inside of a function, where "TRAIT1" is >> a function variable calling a column-name inside of the data.frame >> "new3". >> >> This works just fine: >> >> m2 <- lmer(get(TRAIT1) ~ perm.score + (1|site), data=new3) >> >> but this will not work: >> >> m3 <- lme(get(TRAIT1) ~ perm.score , random= ~1|site, data=new3) >> >> I get the following error: >> >> Error in model.frame.default(formula = ~TRAIT1 + perm.score + site, data >> = list( : >> variable lengths differ (found for 'perm.score') >> >> it seems to be putting TRAIT1 on the left side of the equation, and if I >> am wrong about that, the different lengths from the error is still not >> true: >> >>> length(with(new3, perm.score))==length(with(new3, get(TRAIT1))) >> [1] TRUE >> >> Any ideas on either what is going on, or how I can fix this? >> >> ** I'm not including example data, or function because I am hoping it is >> not needed ** >> Please let me know if I am wrong. >> > -- View this message in context: http://r.789695.n4.nabble.com/problem-with-get-inside-of-lme-tp4629360p4629588.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.