[R] how to search a list that contains multiple dissimilar vectors?
Dear All, This is a simple question, but I'm stumped about the simplest way to search a list object such as the following: This randomish snippet: n - c(round(runif(round(runif(1,1,10),0),1,10),0)) alist - new(list) for (i in seq_along(n)) { alist[[i]] - c(round(runif(round(runif(1,1,10),0),1,10),0)) } names(alist) - sample(letters[1:length(n)]) rm(n);c(alist) ...produces something like this: $d [1] 4 $b [1] 3 5 3 $a [1] 2 5 7 3 10 3 4 9 9 $c [1] 6 3 7 4 5 10 8 10 3 My question is how does one search the list for a given value, in a most compressed set of commands, in order two return two separate indices: a) the index of the list element(s) containing the value, and b) the index of the matching value(s) within the vector. Right now, I'm writing cumbersome loops to iterate though the elements, but there must be a simple, effective method to which I have not found a reference. Many thanks in advance, and apologies if I have overlooked a reference passage. Best, Eric -- Eric Rupley University of Michigan, Museum of Anthropology 1109 Geddes Ave, Rm. 4013 Ann Arbor, MI 48109-1079 __ 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 call R in PHP
Hi, rapache.net is definitely worth to check. And also rook from the same author (Jeffrey Horner). Best, Gergely On 28 March 2013 03:19, Lauren Zhang zxj19880...@yahoo.cn wrote: Hi, I met tough problems when calling R in PHP. I have tried several ways, but none of them succeed. first of all, I tried Rserve, but I failed to connect to it. Then, I tried cmd.exe. I get the result when I use R CMD BATCH --vanilla... in cmd, but I have no idea how to call cmd in php. I know system() is good to call other systems, I triedbut I get no result in my html page. if you could provide some suggestion or examples, i would appreciate your help. the code in my php is£º $cmd=R CMD BATCH--vanilla --slave delete.r; $res=system($cmd); the code in the delete.r file is: setwd(c://wamp//www//analysis); x-4; y-3; z-x*y; sink(125.txt); png(file=125.png); barplot(z,border=dark blue) title(main=list(earning of comparison,font=4)); plot(x,z); dev.off() [[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 search a list that contains multiple dissimilar vectors?
Hi Eric, something like the following might me a starter (index-lapply(alist,function(x)which(x==x.search))) cheers. Am 28.03.2013 08:40, schrieb Eric Rupley: Dear All, This is a simple question, but I'm stumped about the simplest way to search a list object such as the following: This randomish snippet: n - c(round(runif(round(runif(1,1,10),0),1,10),0)) alist - new(list) for (i in seq_along(n)) { alist[[i]] - c(round(runif(round(runif(1,1,10),0),1,10),0)) } names(alist) - sample(letters[1:length(n)]) rm(n);c(alist) ...produces something like this: $d [1] 4 $b [1] 3 5 3 $a [1] 2 5 7 3 10 3 4 9 9 $c [1] 6 3 7 4 5 10 8 10 3 My question is how does one search the list for a given value, in a most compressed set of commands, in order two return two separate indices: a) the index of the list element(s) containing the value, and b) the index of the matching value(s) within the vector. Right now, I'm writing cumbersome loops to iterate though the elements, but there must be a simple, effective method to which I have not found a reference. Many thanks in advance, and apologies if I have overlooked a reference passage. Best, Eric -- Eric Rupley University of Michigan, Museum of Anthropology 1109 Geddes Ave, Rm. 4013 Ann Arbor, MI 48109-1079 __ 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. -- Eik Vettorazzi Department of Medical Biometry and Epidemiology University Medical Center Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus __ 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 search in each excel in my working dir and extract part information of one product in each country?
Hello, I have created many excel files in my working dir. each excel file contain one country's data. In the excel, I have dataframe in sheet1, where each product and its relative information is in each row as following: ProductPERetail_price_Band Country Model_Fit A -2.5 0-50 CN 84% B -2.1 51-100 CN90% . not every product presents in each country, in other words, they may have common products or not. How do I create program in R to search each excel file in my working dir in order to make the list of the such product for each country based on my input(for example, I want to have all information related to product B in each country) the result what I want: ProductPERetail_price_Band Country Model_Fit B -2.4 51-100IN 80% B -2.1 51-100 CN90% How do I achieve this? thanks. Kind regards, Lingyi [[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 search a list that contains multiple dissimilarvectors?
Hi, Eric, as a quick hack, does spots - sapply( alist, function( listcomp) which( listcomp == value.to.look.for) ) spots[ sapply( spots, length) == 0] - NULL do what you want? Regards -- Gerrit On Thu, 28 Mar 2013, Eric Rupley wrote: Dear All, This is a simple question, but I'm stumped about the simplest way to search a list object such as the following: This randomish snippet: n - c(round(runif(round(runif(1,1,10),0),1,10),0)) alist - new(list) for (i in seq_along(n)) { alist[[i]] - c(round(runif(round(runif(1,1,10),0),1,10),0)) } names(alist) - sample(letters[1:length(n)]) rm(n);c(alist) ...produces something like this: $d [1] 4 $b [1] 3 5 3 $a [1] 2 5 7 3 10 3 4 9 9 $c [1] 6 3 7 4 5 10 8 10 3 My question is how does one search the list for a given value, in a most compressed set of commands, in order two return two separate indices: a) the index of the list element(s) containing the value, and b) the index of the matching value(s) within the vector. Right now, I'm writing cumbersome loops to iterate though the elements, but there must be a simple, effective method to which I have not found a reference. Many thanks in advance, and apologies if I have overlooked a reference passage. Best, Eric -- Eric Rupley University of Michigan, Museum of Anthropology 1109 Geddes Ave, Rm. 4013 Ann Arbor, MI 48109-1079 __ 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] question about attaching data
Hi I just would like to know, When I have a dataframe, like this one called 'dummy' And I attach it. Then I run my code. I then update the dataframe by making changes and I still call it 'dummy'. I run my code again. Now dummy is at position 1 and position 2 of the search path and if I run the code again, with another version of 'dummy' it updates and eventually my search path looks like this [1] .GlobalEnvdummy dummy [4] dummy package:stats package:graphics [7] package:grDevices package:datasets package:rcom [10] package:rscproxy package:utils package:methods [13] RExcelEnv Autoloads package:base I get the correct data, as the previous versions of dummy are 'masked from the search path'. What stops me from continuing this process ad infinitum? What's the use of detaching dummy using detach()? Thanks Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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 delete Identical columns
Dear R forum Suppose I have a data.frame df = data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38, 55, 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c(D, B, A, F, H, P)) df id x y x.1 z 1 1 15 36 15 D 2 2 21 38 21 B 3 3 14 55 14 A 4 4 21 11 21 F 5 5 14 5 14 H 6 6 38 18 38 P Clearly columns x and x.1 are identical. In reality, I have a large data.frame and can't make out which columns are identical, but I am sure that column with name say x is repeated as x.1, x.2 etc. How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). Regards Katherine [[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] question about attaching data
Hi, Pancho, 1. Quote: PLEASE do ... provide commented, minimal, self-contained, reproducible code. 2. Changes of variables of attached data frames are -- usually -- not permanent (i.e., disappear when the data frame is detached again). 3. The of use detach( dummy) is to detach the data frame named dummy from the search path, i.e., to take it out of the search path agin. 4. No one is going to stop you from continuing this process ad infinitum except yourself. ;-) HtH -- Gerrit On Thu, 28 Mar 2013, Pancho Mulongeni wrote: Hi I just would like to know, When I have a dataframe, like this one called 'dummy' And I attach it. Then I run my code. I then update the dataframe by making changes and I still call it 'dummy'. I run my code again. Now dummy is at position 1 and position 2 of the search path and if I run the code again, with another version of 'dummy' it updates and eventually my search path looks like this [1] .GlobalEnvdummy dummy [4] dummy package:stats package:graphics [7] package:grDevices package:datasets package:rcom [10] package:rscproxy package:utils package:methods [13] RExcelEnv Autoloads package:base I get the correct data, as the previous versions of dummy are 'masked from the search path'. What stops me from continuing this process ad infinitum? What's the use of detaching dummy using detach()? Thanks Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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] How to delete Identical columns
Hi, Katherine, IF the naming scheme of the columns of your data frame is consistently stringwithoutdot and stringwithoutdot.number if duplicated columns appear THEN (something like) df[ -grep( \\., names( df))] could help. (But it's maybe more efficient to avoid - a priori - producing duplicated columns, if the data frame is large, as you say.) Regards -- Gerrit On Thu, 28 Mar 2013, Katherine Gobin wrote: Dear R forum Suppose I have a data.frame df = data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38, 55, 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c(D, B, A, F, H, P)) df id x y x.1 z 1 1 15 36 15 D 2 2 21 38 21 B 3 3 14 55 14 A 4 4 21 11 21 F 5 5 14 5 14 H 6 6 38 18 38 P Clearly columns x and x.1 are identical. In reality, I have a large data.frame and can't make out which columns are identical, but I am sure that column with name say x is repeated as x.1, x.2 etc. How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). Regards Katherine__ 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] T-shirt
Good morning to the German readers, I'm thinking about getting me a t-shirt with the proverb R-kenntnis ist der erste Schritt auf dem Weg zur Besserung (awareness is the first step towards improvement, the pun being that the first word can also be read as R-knowledge) 1. Could there be a problem using the R-logo? 2. Would anyone else want it? That would make it cheaper. 3. if(2.): Is there a good way to achieve that without me mailing 50 shirts? I have no experience with merchandising... 4. Any other good R-slogans? Let's discuss here, where I also propose a layout: http://RclickHandbuch.wordpress.com/t-shirt I'll update the list, if major insights make that necessary. Berry __ 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 delete Identical columns
Dear Sir, Thanks a lot for your wonderful solution. When I applied it my data.frame, however, it was deleting many other columns also having repeated type of column names i.e. suppose I wanted only to delete say ABC.1, ABC.2 etc. and retain XYZ, XYZ.1, XYZ2 etc. But this was not happening and alongwith ABC series, it was deleting XYZ series too. So I changed the command you had given as - df[ -grep( \\., names( df))] to df[ -grep( XYZ\\., names( df))] And it lead me to the desired result. Thanks again sir. Regards Katherine --- On Thu, 28/3/13, Gerrit Eichner gerrit.eich...@math.uni-giessen.de wrote: From: Gerrit Eichner gerrit.eich...@math.uni-giessen.de Subject: Re: [R] How to delete Identical columns To: Katherine Gobin katherine_go...@yahoo.com Cc: r-help@r-project.org Date: Thursday, 28 March, 2013, 8:58 AM Hi, Katherine, IF the naming scheme of the columns of your data frame is consistently stringwithoutdot and stringwithoutdot.number if duplicated columns appear THEN (something like) df[ -grep( \\., names( df))] could help. (But it's maybe more efficient to avoid - a priori - producing duplicated columns, if the data frame is large, as you say.) Regards -- Gerrit On Thu, 28 Mar 2013, Katherine Gobin wrote: Dear R forum Suppose I have a data.frame df = data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38, 55, 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c(D, B, A, F, H, P)) df id x y x.1 z 1 1 15 36 15 D 2 2 21 38 21 B 3 3 14 55 14 A 4 4 21 11 21 F 5 5 14 5 14 H 6 6 38 18 38 P Clearly columns x and x.1 are identical. In reality, I have a large data.frame and can't make out which columns are identical, but I am sure that column with name say x is repeated as x.1, x.2 etc. How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). Regards Katherine [[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] scatterplot3d with densCols ?
Hi, I was trying to make a 3D plot using densCols. The documentation for densCols doesn't look like it'll work for 3D. For example: - library(scatterplot3d) v1 - rnorm(1) v2 - rnorm(1) v3 - rnorm(1) ## 2D with denscols mat1 - cbind(v1,v2) mcols1 - densCols(mat1) plot(mat1,col=mcols1) mat - cbind(v1,v2,v3) mcols - densCols(mat) ## No go? ## 3D version with no densCols parameter scatterplot3d(mat,pch=16) ## gives error scatterplot3d(mat,col=mcols,pch=16) - Is there any workaround/modification to the densCols function that might make this work? 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.
Re: [R] How to delete Identical columns
this might screw up the column classes of some of your columns, but it could be enough for what you're doing :) # start with a data frame with duplicate columns v - data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38, 55, 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c(D, B, A, F, H, P)) # remove column names names( v ) - NULL # transpose w - t( v ) # remove duplicate rows x - unique( w ) # transpose again y - t( x ) # convert back to data frame z - data.frame( y ) On Thu, Mar 28, 2013 at 4:39 AM, Katherine Gobin katherine_go...@yahoo.comwrote: Dear R forum Suppose I have a data.frame df = data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38, 55, 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c(D, B, A, F, H, P)) df id x yx.1 z 1 1 15 36 15 D 2 2 21 38 21 B 3 3 14 55 14 A 4 4 21 11 21 F 5 5 14 5 14 H 6 6 38 18 38 P Clearly columns x and x.1 are identical. In reality, I have a large data.frame and can't make out which columns are identical, but I am sure that column with name say x is repeated as x.1, x.2 etc. How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). Regards Katherine [[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] scatterplot3d with densCols ?
Hello, According to ?scatterplot3d, the option is 'color', not 'col'. scatterplot3d(mat,color=mcols,pch=16) HTH, Pascal On 28/03/13 19:41, Brian Smith wrote: Hi, I was trying to make a 3D plot using densCols. The documentation for densCols doesn't look like it'll work for 3D. For example: - library(scatterplot3d) v1 - rnorm(1) v2 - rnorm(1) v3 - rnorm(1) ## 2D with denscols mat1 - cbind(v1,v2) mcols1 - densCols(mat1) plot(mat1,col=mcols1) mat - cbind(v1,v2,v3) mcols - densCols(mat) ## No go? ## 3D version with no densCols parameter scatterplot3d(mat,pch=16) ## gives error scatterplot3d(mat,col=mcols,pch=16) - Is there any workaround/modification to the densCols function that might make this work? 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-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] E-learning environment for R
Hello, Does an e-learning environment for R (in English) exist? I would like to point out to students a way to learn R if they have missed the course on R. Pekka Pere University Lecturer University of Helsinki __ 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] scatterplot3d with densCols ?
Ah, yes, correct - the option is color. However, I think the problem (i.e. MY problem) is with densCols - I need it to calculate the 3D density! thanks! On Thu, Mar 28, 2013 at 6:52 AM, Pascal Oettli kri...@ymail.com wrote: Hello, According to ?scatterplot3d, the option is 'color', not 'col'. scatterplot3d(mat,color=mcols,**pch=16) HTH, Pascal On 28/03/13 19:41, Brian Smith wrote: Hi, I was trying to make a 3D plot using densCols. The documentation for densCols doesn't look like it'll work for 3D. For example: --**--- library(scatterplot3d) v1 - rnorm(1) v2 - rnorm(1) v3 - rnorm(1) ## 2D with denscols mat1 - cbind(v1,v2) mcols1 - densCols(mat1) plot(mat1,col=mcols1) mat - cbind(v1,v2,v3) mcols - densCols(mat) ## No go? ## 3D version with no densCols parameter scatterplot3d(mat,pch=16) ## gives error scatterplot3d(mat,col=mcols,**pch=16) --**--- Is there any workaround/modification to the densCols function that might make this work? thanks! [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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.
[R] make R program faster
Hi there are some good tips in The R Inferno http://www.burns-stat.com/documents/books/the-r-inferno/ or connect C++ to R with Rcpp http://dirk.eddelbuettel.com/code/rcpp.html or byte code compiler (library(compiler)) or library(data.table) but do you have an idea to fasten standard R source code, with the following Rprof output self.time self.pct total.time total.pct [-.data.frame 1.3429.13 1.78 38.70 [.data.frame 0.26 5.65 1.02 22.17 [[ 0.12 2.61 0.44 9.57 NextMethod 0.12 2.61 0.12 2.61 match0.10 2.17 0.16 3.48 Anonymous 0.10 2.17 0.10 2.17 c0.10 2.17 0.10 2.17 [[.data.frame0.08 1.74 0.32 6.96 [.Date 0.06 1.30 0.10 2.17 FUN 0.06 1.30 0.10 2.17 [- 0.04 0.87 1.82 39.57 [0.04 0.87 1.04 22.61 [-.Date 0.04 0.87 0.18 3.91 vapply 0.04 0.87 0.14 3.04 %in% 0.02 0.43 0.18 3.91 +0.02 0.43 0.10 2.17 It comes from a simulation algorithmus that calculates day wise values (values are depenend from the output of the day before). First I create a data.frame with NAs. Finally each row contains the daily values. output - as.data.frame(matrix(nrow = 365, ncol = 50)) for (day in (1:365)) { ... r - list(Date=d,daylength=daylength,TempSum=tempsum, ...) output[day,] - r } Is there an better (faster) way to do such things in R? Greetings Christof __ 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] E-learning environment for R
Does 'Try R' suit your requirements? http://tryr.codeschool.com/ Pat On 28/03/2013 07:05, Pekka Pere wrote: Hello, Does an e-learning environment for R (in English) exist? I would like to point out to students a way to learn R if they have missed the course on R. Pekka Pere University Lecturer University of Helsinki __ 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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') __ 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] make R program faster
On 13-03-28 7:07 AM, Christof Kluß wrote: Hi there are some good tips in The R Inferno http://www.burns-stat.com/documents/books/the-r-inferno/ or connect C++ to R with Rcpp http://dirk.eddelbuettel.com/code/rcpp.html or byte code compiler (library(compiler)) or library(data.table) but do you have an idea to fasten standard R source code, with the following Rprof output self.time self.pct total.time total.pct [-.data.frame 1.3429.13 1.78 38.70 [.data.frame 0.26 5.65 1.02 22.17 [[ 0.12 2.61 0.44 9.57 NextMethod 0.12 2.61 0.12 2.61 match0.10 2.17 0.16 3.48 Anonymous 0.10 2.17 0.10 2.17 c0.10 2.17 0.10 2.17 [[.data.frame0.08 1.74 0.32 6.96 [.Date 0.06 1.30 0.10 2.17 FUN 0.06 1.30 0.10 2.17 [- 0.04 0.87 1.82 39.57 [0.04 0.87 1.04 22.61 [-.Date 0.04 0.87 0.18 3.91 vapply 0.04 0.87 0.14 3.04 %in% 0.02 0.43 0.18 3.91 +0.02 0.43 0.10 2.17 It comes from a simulation algorithmus that calculates day wise values (values are depenend from the output of the day before). First I create a data.frame with NAs. Finally each row contains the daily values. output - as.data.frame(matrix(nrow = 365, ncol = 50)) for (day in (1:365)) { ... r - list(Date=d,daylength=daylength,TempSum=tempsum, ...) output[day,] - r } Is there an better (faster) way to do such things in R? Generally matrices are much faster than dataframes. Your code spends about 35-60% of its time in dataframe indexing methods, so you might be able to double the speed by switching to matrices. The disadvantage is that matrices can only hold one type, so you may need multiple matrices to replace one dataframe, and that will make your code harder to read. Duncan Murdoch __ 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] Can R read in .xyz files
Hi, Can R read in .xyz files? If so, what is the package, thanks -- Shane [[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] Can R read in .xyz files
What created your xyz files? File extensions aren't unique. What kind of data do they contain? At least some kinds of xyz files are plain text and can be read with read.table. Sarah On Thursday, March 28, 2013, Shane Carey wrote: Hi, Can R read in .xyz files? If so, what is the package, thanks -- Shane [[alternative HTML version deleted]] __ R-help@r-project.org javascript:; 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. -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[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] Can R read in .xyz files
Shane, you replied to just to me rather than the list. I'm not familiar with geosoft, but the name suggests this might be a better question for r-sig-geo than here. Is the file binary or text? The internet suggests that it's a text format. Have you tried using www.rseek.org to search for import options? You could probably rig something up with scan(). Sarah On Thursday, March 28, 2013, Shane Carey wrote: It was created using a software called geosoft. Ive tried read.table already, but no joy. Thanks On Thu, Mar 28, 2013 at 12:38 PM, Sarah Goslee sarah.gos...@gmail.comjavascript:_e({}, 'cvml', 'sarah.gos...@gmail.com'); wrote: What created your xyz files? File extensions aren't unique. What kind of data do they contain? At least some kinds of xyz files are plain text and can be read with read.table. Sarah On Thursday, March 28, 2013, Shane Carey wrote: Hi, Can R read in .xyz files? If so, what is the package, thanks -- Shane -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[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] Can R read in .xyz files
The advice is wise, despite appearances the extension really means nothing except when it is assumed that it does. Try the raster or rgdal packages, and the R-Sig-Geo mailing list with much more detail (as requested). require(raster) d - raster(somefile) d - rasterFromXYZ(somefile) require(rgdal) d - readGDAL(somefile) All of these are worth trying, and reporting on in detail (read the posting guide). If any of them work they are all achievable and/or provided with more generic R tools, but your original query doesn't provide any information at all to help. Cheers, Mike. On Thu, Mar 28, 2013 at 11:45 PM, Sarah Goslee sarah.gos...@gmail.comwrote: Shane, you replied to just to me rather than the list. I'm not familiar with geosoft, but the name suggests this might be a better question for r-sig-geo than here. Is the file binary or text? The internet suggests that it's a text format. Have you tried using www.rseek.org to search for import options? You could probably rig something up with scan(). Sarah On Thursday, March 28, 2013, Shane Carey wrote: It was created using a software called geosoft. Ive tried read.table already, but no joy. Thanks On Thu, Mar 28, 2013 at 12:38 PM, Sarah Goslee sarah.gos...@gmail.comjavascript:_e({}, 'cvml', 'sarah.gos...@gmail.com'); wrote: What created your xyz files? File extensions aren't unique. What kind of data do they contain? At least some kinds of xyz files are plain text and can be read with read.table. Sarah On Thursday, March 28, 2013, Shane Carey wrote: Hi, Can R read in .xyz files? If so, what is the package, thanks -- Shane -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[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. -- Michael Sumner Hobart, Australia e-mail: mdsum...@gmail.com [[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 delete Identical columns
Hi Katherine, May be this helps: df[!duplicated(lapply(df,summary))] # id x y z #1 1 15 36 D #2 2 21 38 B #3 3 14 55 A #4 4 21 11 F #5 5 14 5 H #6 6 38 18 P #or df[,colnames(unique(as.matrix(df),MARGIN=2))] # id x y z #1 1 15 36 D #2 2 21 38 B #3 3 14 55 A #4 4 21 11 F #5 5 14 5 H #6 6 38 18 P A.K. - Original Message - From: Katherine Gobin katherine_go...@yahoo.com To: r-help@r-project.org Cc: Sent: Thursday, March 28, 2013 4:39 AM Subject: [R] How to delete Identical columns Dear R forum Suppose I have a data.frame df = data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38, 55, 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c(D, B, A, F, H, P)) df id x y x.1 z 1 1 15 36 15 D 2 2 21 38 21 B 3 3 14 55 14 A 4 4 21 11 21 F 5 5 14 5 14 H 6 6 38 18 38 P Clearly columns x and x.1 are identical. In reality, I have a large data.frame and can't make out which columns are identical, but I am sure that column with name say x is repeated as x.1, x.2 etc. How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). Regards Katherine [[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] How to search in each excel in my working dir and extract part information of one product in each country?
-Original Message- From: metal_lical...@live.com Sent: Thu, 28 Mar 2013 11:24:43 +0300 To: r-help@r-project.org Subject: [R] How to search in each excel in my working dir and extract part information of one product in each country? Hello, I have created many excel files in my working dir. Why? each excel file contain one country's data. In the excel, I have dataframe in sheet1, where each product and its relative information is in each row as following: ProductPERetail_price_Band Country Model_Fit A -2.5 0-50 CN 84% B -2.1 51-100 CN90% . not every product presents in each country, in other words, they may have common products or not. How do I create program in R to search each excel file in my working dir in order to make the list of the such product for each country based on my input(for example, I want to have all information related to product B in each country) the result what I want: ProductPERetail_price_Band Country Model_Fit B -2.4 51-100IN 80% B -2.1 51-100 CN90% How do I achieve this? thanks. Kind regards, Lingyi If you are doing the original analyses in R why not just run them put the results for the countries in a list. Then just convert the list to a data.frame and subset. Quick and dirty example. md1 - data.frame(aa = 1:10, b = letters[1:5]) md2 - data.frame(aa = 11:20, b = letters[6:10]) mlist - list(md1,md2) dd1 - do.call(rbind.data.frame, mlist) FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ 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] new question
Hi, Try this: Spec - function(lista,FDR_k) { list.new-lapply(lista,function(x) within(x,{spec- as.character(spec)})) split.list-split(list.new,names(lista)) #Data needed with FDRFDR_k seq.mod.z-lapply(seq_along(split.list),function(i) lapply(split.list[[i]],function(x) x[x[[FDR]]FDR_k,c(Seq,Mod,z,spec)])) names(seq.mod.z)- names(split.list) #insert colunm with the name of the folder folder.name-lapply(seq.mod.z,function(x) lapply(names(x),function(i) do.call(rbind,lapply(x[i],function(x) cbind(folder_name=i,x) #merge data with the same Seq, Mod and z library(plyr) library(data.table) merge.data- lapply(folder.name,function(x) lapply(x,function(x1) {x1-data.table(x1); x1[,spec:=paste(spec,collapse=,),by=c(Seq,Mod,z)]})) #colunm with number of spec count.spec-lapply(merge.data,function(x) lapply(x,function(x1) {x1$counts-sapply(x1$spec, function(x2) length(gsub(\\s, , unlist(strsplit(x2, ,);x3-as.data.frame(x1);names(x3)[6]- as.character(unique(x3$folder_name));x3[,-c(1,5)]})) count.specUnique-lapply(count.spec,function(x) lapply(x,unique)) #count spec by group (2-columns) spec.group-lapply(count.specUnique,function(x) Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),x)) #spec.group1-spec.group[lapply(spec.group,length)!=0] #data frame with count of spec res- Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),spec.group) res[is.na(res)] - 0 res- as.data.frame(res,stringsAsFactors=FALSE) print(res) } Spec(ListFacGroup,0.05) # Seq Mod z a2 c2 c3 t2 #1 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 #2 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 #3 aAGAAGGR 1-n_acPro/ 2 1 1 0 1 #4 AAALQAK 2 1 0 1 1 #5 aAGAGPEMVR 1-n_acPro/ 2 2 2 1 2 #6 aEQQQFYLLLGNLLSPDNVVR 1-_Carbamoylation/ 2 1 0 0 1 #7 aEQQQFYLLLGNLLSPDNVVR 1-_Carbamoylation/ 3 1 0 0 1 #8 aEQQQFYLLLGNLLSPDNVVR 1-n_acPro/ 2 0 1 0 0 #9 aEQQQFYLLLGNLLSPDNVVR 1-n_acPro/ 3 1 2 2 1 #10 APGTAEK 2 0 1 0 0 #11 aSAPQQLSDEELFSQLR 1-n_acPro/ 2 1 0 0 1 #12 aVGNAVPCGAR 1-n_acPro/ 2 1 1 1 1 #13 AWEEPSSGNGTAR 2 1 1 1 1 #14 aAAAELSLLEK 1-n_acPro/ 1 1 0 0 1 #15 aAAAELSLLEK 1-n_acPro/ 2 1 1 1 1 #16 EVLGLILR 2 1 1 1 1 #17 aAAAGAAAEGEAPAEMGALLLEK 1-n_acPro/ 3 1 1 1 1 #18 aAAAPGTAVGATGSGIAGLAVYR 1-_Carbamoylation/ 3 0 0 1 0 #19 aAAAPGTAVGATGSGIAGLAVYR 1-n_acPro/ 3 1 0 0 1 #20 aAAANSGSSLPLFDCPTWAGKPPPGLHLDVVK 1-n_acPro/ 3 1 0 0 1 #21 AAAkAAK 8-K_ac/ 2 0 1 0 0 #22 aAAAVGAGHGAGGPGAASSSGGAR 1-n_acPro/ 2 0 1 1 0 #23 aAAAVGAGHGAGGPGAASSSGGAR 1-n_acPro/ 3 0 0 1 0 #24 aAADGDDSLYPIAVLIDELR 1-n_acPro/ 2 0 0 1 0 Regarding the 2nd question, I am a bit busy now. Will try it later. A.K. From: Vera Costa veracosta...@gmail.com To: arun smartpink...@yahoo.com Sent: Thursday, March 28, 2013 9:43 AM Subject: Re: new question I don't remove duplicated, but write only one time. If I haven't unique I have the same row a lot of times, but with unique we remove all. I need this row write only one time. without unique the output is 1 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 2 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 3 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 4 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 5 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 6 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 7 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 8 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 9 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 10 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 11 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 12 aAGAAGGR 1-n_acPro/ 2 1 1 0 1 13 AAALQAK 2 1 0 1 1 14 aAGAGPEMVR 1-n_acPro/ 2 2 2 1 2 15 aEQQQFYLLLGNLLSPDNVVR 1-_Carbamoylation/ 2 1 0 0 1 16 aEQQQFYLLLGNLLSPDNVVR 1-_Carbamoylation/ 3 1 0 0 1 17 aEQQQFYLLLGNLLSPDNVVR 1-n_acPro/ 2 0 1 0 0 18 aEQQQFYLLLGNLLSPDNVVR 1-n_acPro/ 3 1 2
Re: [R] How to delete Identical columns
On Mar 28, 2013, at 1:39 AM, Katherine Gobin wrote: Dear R forum Suppose I have a data.frame df = data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38, 55, 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c(D, B, A, F, H, P)) df id x yx.1 z 1 1 15 36 15 D 2 2 21 38 21 B 3 3 14 55 14 A 4 4 21 11 21 F 5 5 14 5 14 H 6 6 38 18 38 P Clearly columns x and x.1 are identical. In reality, I have a large data.frame and can't make out which columns are identical, but I am sure that column with name say x is repeated as x.1, x.2 etc. How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). df[!duplicated(as.list(df))] id x y z 1 1 15 36 D 2 2 21 38 B 3 3 14 55 A 4 4 21 11 F 5 5 14 5 H 6 6 38 18 P Regards Katherine [[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. 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] Read text file in R
con-file(RRoutall.txt) Lines1- readLines(con) close(con) indx-rep(rep(c(TRUE,FALSE),each=2),22) Lines2-Lines1[!grepl([A-Za-z],Lines1)] res-read.table(text=paste(gsub(^\\s+,,Lines2[indx]),gsub(^\\s+,,Lines2[!indx])),sep=,header=FALSE) nm1-unlist(strsplit(gsub(^ +,,paste(Lines1[grepl([A-Za-z],Lines1)][1:2],collapse= )), )) colnames(res)- nm1[nm1!=] head(res) # m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error N #1 8 4 12 10 0.68152 0.53348 0.03 0.03 0.15 0.15 0.1 0.2 0.41218 22 #2 8 4 12 10 0.68152 0.53348 0.03 0.03 0.15 0.15 0.1 0.2 0.41218 22 #3 8 4 12 9 0.68152 0.53348 0.03 0.03 0.15 0.20 0.1 0.2 0.42356 21 #4 8 4 12 9 0.68152 0.53348 0.03 0.03 0.15 0.20 0.1 0.2 0.42356 21 #5 8 4 12 8 0.68152 0.53348 0.03 0.03 0.15 0.25 0.1 0.2 0.47058 20 #6 8 4 12 8 0.68152 0.53348 0.03 0.03 0.15 0.25 0.1 0.2 0.47058 20 # EN BH BL AH AL #1 16.073 0.086514 0.19448 0.092756 0.038431 #2 16.073 0.086514 0.19448 0.092756 0.038431 #3 15.607 0.131028 0.18599 0.064031 0.042514 #4 15.607 0.131028 0.18599 0.064031 0.042514 #5 15.140 0.193348 0.19418 0.043383 0.039667 #6 15.140 0.193348 0.19418 0.043383 0.039667 A.K. From: Joanna Zhang zjoanna2...@gmail.com T o: arun smartpink...@yahoo.com Sent: Thursday, March 28, 2013 11:26 AM Subject: Re: Read text file in R Hi, got another output file, there is an error when reading it using the code: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 47 did not have 19 elements On Mon, Mar 25, 2013 at 12:32 PM, arun smartpink...@yahoo.com wrote: res[res$EN==min(res$EN),] # m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error #25 9 4 13 12 0.6302494 0.7565041 0.03 0.07 0.15 0.15 0.1 0.2 0.4403712 #27 9 4 13 12 0.6302494 0.7565041 0.03 0.07 0.15 0.20 0.1 0.2 0.4473437 #33 9 4 13 12 0.6302494 0.7565041 0.05 0.07 0.15 0.15 0.1 0.2 0.4403712 #35 9 4 13 12 0.6302494 0.7565041 0.05 0.07 0.15 0.20 0.1 0.2 0.4473437 N EN BH BL AH AL #25 25 16.42697 0.1201138 0.1933632 0.09321455 0.03367957 #27 25 16.42697 0.1553998 0.1933632 0.06490110 0.03367957 #33 25 16.42697 0.1201138 0.1933632 0.09321455 0.03367957 #35 25 16.42697 0.1553998 0.1933632 0.06490110 0.03367957 A.K. From: Joanna Zhang zjoanna2...@gmail.com To: arun smartpink...@yahoo.com Sent: Monday, March 25, 2013 12:13 PM Subject: Re: Read text file in R Great! When I tried to extract the min of EN, it has an error; opt-con[con$EN==min(con$EN),] opt Error in con$EN : $ operator is invalid for atomic vectors On Mon, Mar 25, 2013 at 11:05 AM, arun smartpink...@yahoo.com wrote: Hi, Try this: con-file(Routallnew.txt) Lines1- readLines(con) close(con) indx-rep(rep(c(TRUE,FALSE),each=2),24) Lines2-Lines1[!grepl([A-Za-z],Lines1)] res-read.table(text=paste(gsub(^\\s+,,Lines2[indx]),gsub(^\\s+,,Lines2[!indx])),sep=,header=FALSE) nm1-unlist(strsplit(gsub(^ +,,paste(Lines1[grepl([A-Za-z],Lines1)][1:2],collapse= )), )) colnames(res)- nm1[nm1!=] head(res) # m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error N #1 13 5 17 9 0.7851203 0.6689925 0.03 0.03 0.15 0.15 0.1 0.2 0.3669373 26 #2 13 5 17 9 0.7851203 0.6689925 0.03 0.03 0.15 0.15 0.1 0.2 0.3669373 26 #3 9 5 13 11 0.6302494 0.4876750 0.03 0.03 0.15 0.20 0.1 0.2 0.4137296 24 #4 9 5 13 11 0.6302494 0.4876750 0.03 0.03 0.15 0.20 0.1 0.2 0.4137296 24 #5 9 5 13 11 0.6302494 0.4876750 0.03 0.03 0.15 0.25 0.1 0.2 0.4782406 24 #6 9 5 13 11 0.6302494 0.4876750 0.03 0.03 0.15 0.25 0.1 0.2 0.4782406 24 # EN BH BL AH AL #1 20.18355 0.07718537 0.1865207 0.08079875 0.02243240 #2 20.18355 0.07718537 0.1865207 0.08079875 0.02243240 #3 18.55295 0.08482219 0.1996013 0.09569044 0.03361565 #4 18.55295 0.08482219 0.1996013 0.09569044 0.03361565 #5 18.55295 0.19596330 0.1996013 0.04906038 0.03361565 #6 18.55295 0.19596330 0.1996013 0.04906038 0.03361565 A.K. From: Joanna Zhang zjoanna2...@gmail.com To: arun smartpink...@yahoo.com Sent: Monday, March 25, 2013 11:19 AM Subject: Read text file in R Hi Arun, I just sent you a text file via R, but I think it is being held for moderator approval. I attached the final output file here, could you help me read it in R when you have time? __ 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 copy current line in Tinn-R
Thanks, that works, however I was hoping for a keyboard shortcut. On 3/26/2013 11:43, John Kane wrote: I hve not used Tinn-R in a while (I'm currently running Ubuntu) but I think that you can just click in the left margin to select the line. John Kane Kingston ON Canada -Original Message- From: f...@dmu.dk Sent: Mon, 25 Mar 2013 11:33:28 +0100 To: r-help@r-project.org Subject: [R] How to copy current line in Tinn-R Hello All, A very simple question about Tinn-R. I am able to use the send line shortcut, but I want to be able to just copy the current line to the clipboard and then paste in the current document or somewhere else. It's so tedious to select the whole line and then copy it. Thanks __ 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. FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium __ 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] Read text file in R
HI, Just a correction: indx-rep(rep(c(TRUE,FALSE),each=2),23) A.K. - Original Message - From: arun smartpink...@yahoo.com To: Joanna Zhang zjoanna2...@gmail.com Cc: R help r-help@r-project.org Sent: Thursday, March 28, 2013 11:38 AM Subject: Re: [R] Read text file in R con-file(RRoutall.txt) Lines1- readLines(con) close(con) indx-rep(rep(c(TRUE,FALSE),each=2),22) Lines2-Lines1[!grepl([A-Za-z],Lines1)] res-read.table(text=paste(gsub(^\\s+,,Lines2[indx]),gsub(^\\s+,,Lines2[!indx])),sep=,header=FALSE) nm1-unlist(strsplit(gsub(^ +,,paste(Lines1[grepl([A-Za-z],Lines1)][1:2],collapse= )), )) colnames(res)- nm1[nm1!=] head(res) # m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error N #1 8 4 12 10 0.68152 0.53348 0.03 0.03 0.15 0.15 0.1 0.2 0.41218 22 #2 8 4 12 10 0.68152 0.53348 0.03 0.03 0.15 0.15 0.1 0.2 0.41218 22 #3 8 4 12 9 0.68152 0.53348 0.03 0.03 0.15 0.20 0.1 0.2 0.42356 21 #4 8 4 12 9 0.68152 0.53348 0.03 0.03 0.15 0.20 0.1 0.2 0.42356 21 #5 8 4 12 8 0.68152 0.53348 0.03 0.03 0.15 0.25 0.1 0.2 0.47058 20 #6 8 4 12 8 0.68152 0.53348 0.03 0.03 0.15 0.25 0.1 0.2 0.47058 20 # EN BH BL AH AL #1 16.073 0.086514 0.19448 0.092756 0.038431 #2 16.073 0.086514 0.19448 0.092756 0.038431 #3 15.607 0.131028 0.18599 0.064031 0.042514 #4 15.607 0.131028 0.18599 0.064031 0.042514 #5 15.140 0.193348 0.19418 0.043383 0.039667 #6 15.140 0.193348 0.19418 0.043383 0.039667 A.K. From: Joanna Zhang zjoanna2...@gmail.com T o: arun smartpink...@yahoo.com Sent: Thursday, March 28, 2013 11:26 AM Subject: Re: Read text file in R Hi, got another output file, there is an error when reading it using the code: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 47 did not have 19 elements On Mon, Mar 25, 2013 at 12:32 PM, arun smartpink...@yahoo.com wrote: res[res$EN==min(res$EN),] # m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error #25 9 4 13 12 0.6302494 0.7565041 0.03 0.07 0.15 0.15 0.1 0.2 0.4403712 #27 9 4 13 12 0.6302494 0.7565041 0.03 0.07 0.15 0.20 0.1 0.2 0.4473437 #33 9 4 13 12 0.6302494 0.7565041 0.05 0.07 0.15 0.15 0.1 0.2 0.4403712 #35 9 4 13 12 0.6302494 0.7565041 0.05 0.07 0.15 0.20 0.1 0.2 0.4473437 N EN BH BL AH AL #25 25 16.42697 0.1201138 0.1933632 0.09321455 0.03367957 #27 25 16.42697 0.1553998 0.1933632 0.06490110 0.03367957 #33 25 16.42697 0.1201138 0.1933632 0.09321455 0.03367957 #35 25 16.42697 0.1553998 0.1933632 0.06490110 0.03367957 A.K. From: Joanna Zhang zjoanna2...@gmail.com To: arun smartpink...@yahoo.com Sent: Monday, March 25, 2013 12:13 PM Subject: Re: Read text file in R Great! When I tried to extract the min of EN, it has an error; opt-con[con$EN==min(con$EN),] opt Error in con$EN : $ operator is invalid for atomic vectors On Mon, Mar 25, 2013 at 11:05 AM, arun smartpink...@yahoo.com wrote: Hi, Try this: con-file(Routallnew.txt) Lines1- readLines(con) close(con) indx-rep(rep(c(TRUE,FALSE),each=2),24) Lines2-Lines1[!grepl([A-Za-z],Lines1)] res-read.table(text=paste(gsub(^\\s+,,Lines2[indx]),gsub(^\\s+,,Lines2[!indx])),sep=,header=FALSE) nm1-unlist(strsplit(gsub(^ +,,paste(Lines1[grepl([A-Za-z],Lines1)][1:2],collapse= )), )) colnames(res)- nm1[nm1!=] head(res) # m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error N #1 13 5 17 9 0.7851203 0.6689925 0.03 0.03 0.15 0.15 0.1 0.2 0.3669373 26 #2 13 5 17 9 0.7851203 0.6689925 0.03 0.03 0.15 0.15 0.1 0.2 0.3669373 26 #3 9 5 13 11 0.6302494 0.4876750 0.03 0.03 0.15 0.20 0.1 0.2 0.4137296 24 #4 9 5 13 11 0.6302494 0.4876750 0.03 0.03 0.15 0.20 0.1 0.2 0.4137296 24 #5 9 5 13 11 0.6302494 0.4876750 0.03 0.03 0.15 0.25 0.1 0.2 0.4782406 24 #6 9 5 13 11 0.6302494 0.4876750 0.03 0.03 0.15 0.25 0.1 0.2 0.4782406 24 # EN BH BL AH AL #1 20.18355 0.07718537 0.1865207 0.08079875 0.02243240 #2 20.18355 0.07718537 0.1865207 0.08079875 0.02243240 #3 18.55295 0.08482219 0.1996013 0.09569044 0.03361565 #4 18.55295 0.08482219 0.1996013 0.09569044 0.03361565 #5 18.55295 0.19596330 0.1996013 0.04906038 0.03361565 #6 18.55295 0.19596330 0.1996013 0.04906038 0.03361565 A.K. From: Joanna Zhang zjoanna2...@gmail.com To: arun smartpink...@yahoo.com Sent: Monday, March 25, 2013 11:19 AM Subject: Read text file in R Hi Arun, I just sent you a text file via R, but I think it is being held for moderator approval. I attached the final output file here, could you help me read it in R when you have time? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
[R] How to replace '$' sign?
Hello again, I want to remove $ sign and replace with nothing in my text. Therefore I used following code: gsub($|,, , $232,685.35436) [1] $232685.35436 However I could not remove '$' sign. Can somebody help me why is it so? Thanks and regards __ 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] bayesian HLM random effects
Hello, all. I've been working on this for sometime and was almost at the end/ last chunk of code i would need When I received an error. Rather than go to bed and think about it in the morning, I messed with my data and now I am not getting anything. I was up until 4am trying to fix this. Zip files of my data are attached (the data which ends in 'a' matches with wvsA and the data which ends in 'b' matches with my data code wvsB). my code is below. I can't even get plots, now. If i can just get to that point, i would be eternally grateful for any help. please find my code attached, as well. - __ 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 delete Identical columns
Katherine Gobin katherine_gobin at yahoo.com writes: Dear R forum Suppose I have a data.frame Say. [snip] How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). See ?unique Details This is a generic function with methods for vectors, *data frames* and ... [emphasis added] So, unique( df, MARGIN=2 ) is what you want. HTH, __ 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] unique not working
i am using mac OSX 10.7.5, running R version 2.15.2 (2012-10-26) -- Trick or Treat when i do: uncountry - unique(wvsAB[,7]) wvsAB$numcountry - match(wvsAB$country, uncountry) unstate isn't attaching. library(base) uncountry - unique(wvsAB[,7]) wvsAB$numcountry - match(wvsAB$country, uncountry) ls(wvsAB) [1] agecountrycpidemdiversity educ gender income [9] netnumcountry trust thanks in advance for any help. __ 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 '$' sign?
In regular expressions, $ means the end of the line, so you have to escape it: gsub(\\$|,, , $232,685.3567) [1] 232685.3567 On Thu, Mar 28, 2013 at 11:39 AM, Christofer Bogaso bogaso.christo...@gmail.com wrote: Hello again, I want to remove $ sign and replace with nothing in my text. Therefore I used following code: gsub($|,, , $232,685.35436) [1] $232685.35436 However I could not remove '$' sign. Can somebody help me why is it so? Thanks and regards __ 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[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 '$' sign?
On Mar 28, 2013, at 10:39 AM, Christofer Bogaso bogaso.christo...@gmail.com wrote: Hello again, I want to remove $ sign and replace with nothing in my text. Therefore I used following code: gsub($|,, , $232,685.35436) [1] $232685.35436 However I could not remove '$' sign. Can somebody help me why is it so? Thanks and regards The dollar sign is a metacharacter in regular expressions (see ?regex), thus has to be escaped to be interpreted as a literal character: gsub(\\$|,, , $232,685.35436) [1] 232685.35436 Regards, Marc Schwartz __ 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 '$' sign?
Hi, If you just want to remove the $, it must be escaped because $ is a special character in regular expressions. gsub(\\$, , $232,685.35436) [1] 232,685.35436 But it looks like you actually want to remove both $ and , Modifying your code: gsub(\\$|,, , $232,685.35436) [1] 232685.35436 Or my preferred idiom: gsub([$,], , $232,685.35436) [1] 232685.35436 Sarah On Thu, Mar 28, 2013 at 11:39 AM, Christofer Bogaso bogaso.christo...@gmail.com wrote: Hello again, I want to remove $ sign and replace with nothing in my text. Therefore I used following code: gsub($|,, , $232,685.35436) [1] $232685.35436 However I could not remove '$' sign. Can somebody help me why is it so? Thanks and regards -- Sarah Goslee http://www.functionaldiversity.org __ 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] bayesian HLM random effects
Nicole, this list strips binary attachments. Using dput() is the most effective way to include some of your data, and we also need to see the R code you're trying to use, and some information about what you want to accomplish, all included in the body of your email. Sarah On Thu, Mar 28, 2013 at 9:48 AM, Nicole Ford nicole.f...@me.com wrote: Hello, all. I've been working on this for sometime and was almost at the end/ last chunk of code i would need When I received an error. Rather than go to bed and think about it in the morning, I messed with my data and now I am not getting anything. I was up until 4am trying to fix this. Zip files of my data are attached (the data which ends in 'a' matches with wvsA and the data which ends in 'b' matches with my data code wvsB). my code is below. I can't even get plots, now. If i can just get to that point, i would be eternally grateful for any help. please find my code attached, as well. - -- Sarah Goslee http://www.functionaldiversity.org __ 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] unique not working
Hi, I'm confused. On Thu, Mar 28, 2013 at 10:49 AM, Nicole Ford nicolefor...@gmail.com wrote: i am using mac OSX 10.7.5, running R version 2.15.2 (2012-10-26) -- Trick or Treat when i do: uncountry - unique(wvsAB[,7]) wvsAB$numcountry - match(wvsAB$country, uncountry) unstate isn't attaching. What's unstate? What does isn't attaching mean? Why don't you provide a sample of your data with dput() and tell us what you're trying to accomplish so we can help. library(base) uncountry - unique(wvsAB[,7]) wvsAB$numcountry - match(wvsAB$country, uncountry) ls(wvsAB) [1] agecountrycpidemdiversity educ gender income [9] netnumcountry trust thanks in advance for any help. -- Sarah Goslee http://www.functionaldiversity.org __ 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 search in each excel in my working dir and extract part information of one product in each country?
You can use 'list.files()' to get the list of all the Excel file names and then the XLConnect package makes it easy to read in the files and extract the data that you want from them. On Thu, Mar 28, 2013 at 4:24 AM, Tammy Ma metal_lical...@live.com wrote: Hello, I have created many excel files in my working dir. each excel file contain one country's data. In the excel, I have dataframe in sheet1, where each product and its relative information is in each row as following: ProductPERetail_price_Band Country Model_Fit A -2.5 0-50 CN 84% B -2.1 51-100 CN90% . not every product presents in each country, in other words, they may have common products or not. How do I create program in R to search each excel file in my working dir in order to make the list of the such product for each country based on my input(for example, I want to have all information related to product B in each country) the result what I want: ProductPERetail_price_Band Country Model_Fit B -2.4 51-100IN 80% B -2.1 51-100 CN90% How do I achieve this? thanks. Kind regards, Lingyi [[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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[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 delete Identical columns
Yes, but the elephant in the room is: Define: Identical. If you do not know why this is an elephant, see FAQ 7.31. -- Bert On Thu, Mar 28, 2013 at 8:40 AM, Charles Berry ccbe...@ucsd.edu wrote: Katherine Gobin katherine_gobin at yahoo.com writes: Dear R forum Suppose I have a data.frame Say. [snip] How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). See ?unique Details This is a generic function with methods for vectors, *data frames* and ... [emphasis added] So, unique( df, MARGIN=2 ) is what you want. HTH, __ 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 [[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 delete Identical columns
Charles Berry ccberry at ucsd.edu writes: [snip] Katherine Gobin katherine_gobin at yahoo.com writes: How to automatically identify and retain only one column (in this example column x) among the identical columns besides other non-identical columns (viz. id, y and z). See ?unique Details This is a generic function with methods for vectors, *data frames* and ... [emphasis added] So, unique( df, MARGIN=2 ) is what you want. My bad. Mea culpa, etc. There is a data.frame method, but it ignores the MARGIN arg. Better to stick with what David suggested: http://article.gmane.org/gmane.comp.lang.r.general/289881 HTH, __ 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] plotting interactive networks in R
Sachin, library(igraph) ?tkplot Jean On Wed, Mar 27, 2013 at 7:32 PM, Sachinthaka Abeywardana sachin.abeyward...@gmail.com wrote: Hi all, I was wondering if there was package/ tutorial somewhere so that I can plot INTERACTIVE networks in R. What I mean by interactive is that you can zoom in, twist and rotate, and if necessary move nodes around. Any thoughts? Thanks, Sachin __ 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.
[R] Can R read open office.org Calc files
Hi, Can R read open office.org Calc files Thanks -- Shane [[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] Can R read open office.org Calc files
This might help: http://www.omegahat.org/ROpenOffice/ Rgds, Rainer On Thursday 28 March 2013 17:32:23 Shane Carey wrote: Hi, Can R read open office.org Calc files Thanks __ 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] QUESTION ON ROUNDING
Dear All, wonder if you have a thought on the following: I am using the round(x,digits=3) command, but some of my values come out as: 0.07099 AND 0.06901. Any thoughts on why this maty be happening or how to eliminate the problem? apreciate the help, Andras [[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] Can R read open office.org Calc files
On Mar 28, 2013, at 10:40 AM, Rainer Schuermann wrote: This might help: http://www.omegahat.org/ROpenOffice/ Rgds, Rainer Just to save some people some time, I will add that the ROpenOffice package depends on the RCompression package and will not install on R3.0.0 beta until you also reinstall that package. I needed to download each to my User directory and then run: install.packages(~/Rcompression_0.93-2.tar.gz, repos=NULL, type=source) install.packages(~/ROpenOffice_0.4-0.tar.gz, repos=NULL, type=source) On Thursday 28 March 2013 17:32:23 Shane Carey wrote: Hi, Can R read open office.org Calc files Thanks -- 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] QUESTION ON ROUNDING
On Thu, Mar 28, 2013 at 6:21 PM, Andras Farkas motyoc...@yahoo.com wrote: Dear All, wonder if you have a thought on the following: I am using the round(x,digits=3) command, but some of my values come out as: 0.07099 AND 0.06901. Any thoughts on why this maty be happening or how to eliminate the problem? I'd guess you've played with the default digits for print() (perhaps via options) but a reproducible example would be terribly lovely. MW apreciate the help, Andras [[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] new question
Hi, The function outputs the unique rows and also chisq test on frequency ( by row). Spec - function(lista,FDR_k) { list.new-lapply(lista,function(x) within(x,{spec- as.character(spec)})) split.list-split(list.new,names(lista)) #Data needed with FDRFDR_k seq.mod.z-lapply(seq_along(split.list),function(i) lapply(split.list[[i]],function(x) x[x[[FDR]]FDR_k,c(Seq,Mod,z,spec)])) names(seq.mod.z)- names(split.list) #insert colunm with the name of the folder folder.name-lapply(seq.mod.z,function(x) lapply(names(x),function(i) do.call(rbind,lapply(x[i],function(x) cbind(folder_name=i,x) #merge data with the same Seq, Mod and z library(plyr) library(data.table) merge.data- lapply(folder.name,function(x) lapply(x,function(x1) {x1-data.table(x1); x1[,spec:=paste(spec,collapse=,),by=c(Seq,Mod,z)]})) #colunm with number of spec count.spec-lapply(merge.data,function(x) lapply(x,function(x1) {x1$counts-sapply(x1$spec, function(x2) length(gsub(\\s, , unlist(strsplit(x2, ,);x3-as.data.frame(x1);names(x3)[6]- as.character(unique(x3$folder_name));x3[,-c(1,5)]})) count.specUnique-lapply(count.spec,function(x) lapply(x,unique)) #count spec by group (2-columns) spec.group-lapply(count.specUnique,function(x) Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),x)) #spec.group1-spec.group[lapply(spec.group,length)!=0] #data frame with count of spec res- Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),spec.group) res[is.na(res)] - 0 res- as.data.frame(res,stringsAsFactors=FALSE) #print(res) Chisq1test_Count-do.call(cbind,lapply(as.data.frame(combn(names(res)[4:ncol(res)],2),stringsAsFactors=FALSE),function(x) {x1-data.frame(apply(cbind(res[x[1]],res[x[2]]),1,function(y){ifelse(sum(y)==0, NA, chisq.test(y)$p.value)}));colnames(x1)- paste0(Count_,x[1],x[2]);x1})) #print(Chisq1test_Count) res1- cbind(res,Chisq1test_Count) res1 } ListFacGroup-ReadDir(FacGroup) Spec(ListFacGroup,0.05) head(Spec(ListFacGroup,0.05)) # Seq Mod z a2 c2 c3 t2 Count_a2c2 #1 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 0.02534732 #2 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 0.01430588 #3 aAGAAGGR 1-n_acPro/ 2 1 1 0 1 1. #4 AAALQAK 2 1 0 1 1 0.31731051 #5 aAGAGPEMVR 1-n_acPro/ 2 2 2 1 2 1. #6 aEQQQFYLLLGNLLSPDNVVR 1-_Carbamoylation/ 2 1 0 0 1 0.31731051 # Count_a2c3 Count_a2t2 Count_c2c3 Count_c2t2 Count_c3t2 #1 0.02534732 0.10247043 NA 0.3173105 0.3173105 #2 0.01430588 0.05878172 NA 0.3173105 0.3173105 #3 0.31731051 1. 0.3173105 1.000 0.3173105 #4 1. 1. 0.3173105 0.3173105 1.000 #5 0.56370286 1. 0.5637029 1.000 0.5637029 #6 0.31731051 1. NA 0.3173105 0.3173105 A.K. From: arun smartpink...@yahoo.com To: Vera Costa veracosta...@gmail.com Cc: R help r-help@r-project.org Sent: Thursday, March 28, 2013 10:18 AM Subject: Re: [R] new question Hi, Try this: Spec - function(lista,FDR_k) { list.new-lapply(lista,function(x) within(x,{spec- as.character(spec)})) split.list-split(list.new,names(lista)) #Data needed with FDRFDR_k seq.mod.z-lapply(seq_along(split.list),function(i) lapply(split.list[[i]],function(x) x[x[[FDR]]FDR_k,c(Seq,Mod,z,spec)])) names(seq.mod.z)- names(split.list) #insert colunm with the name of the folder folder.name-lapply(seq.mod.z,function(x) lapply(names(x),function(i) do.call(rbind,lapply(x[i],function(x) cbind(folder_name=i,x) #merge data with the same Seq, Mod and z library(plyr) library(data.table) merge.data- lapply(folder.name,function(x) lapply(x,function(x1) {x1-data.table(x1); x1[,spec:=paste(spec,collapse=,),by=c(Seq,Mod,z)]})) #colunm with number of spec count.spec-lapply(merge.data,function(x) lapply(x,function(x1) {x1$counts-sapply(x1$spec, function(x2) length(gsub(\\s, , unlist(strsplit(x2, ,);x3-as.data.frame(x1);names(x3)[6]- as.character(unique(x3$folder_name));x3[,-c(1,5)]})) count.specUnique-lapply(count.spec,function(x) lapply(x,unique)) #count spec by group (2-columns) spec.group-lapply(count.specUnique,function(x) Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),x)) #spec.group1-spec.group[lapply(spec.group,length)!=0] #data frame with count of spec res- Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),spec.group) res[is.na(res)] - 0 res- as.data.frame(res,stringsAsFactors=FALSE) print(res) } Spec(ListFacGroup,0.05) # Seq Mod z a2 c2 c3 t2 #1 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 #2 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 #3 aAGAAGGR 1-n_acPro/ 2 1 1 0 1 #4 AAALQAK 2 1 0 1 1 #5
[R] Error in setMethod(combine... was - Error when installing globaltest package
Hi All, I posted this on the bioconductor list and didn't get a response there, so I'm hoping someone here can help. I don't know a heck of a lot about R, so I apologize if this seems like a trivial issue. This error comes up when trying to install the bioconductor globaltest package. Any clues? Thanks! Rusty -Original Message- From: bioconductor-boun...@r-project.org [mailto:bioconductor-boun...@r-project.org] On Behalf Of Shields, Rusty (IMS) Sent: Tuesday, March 26, 2013 12:34 PM To: bioconduc...@r-project.org Subject: [BioC] Error when installing globaltest package Hi all, I've run into a problem when attempting to install the globaltest package from Bioconductor. I'm using R 2.14.0 on 64bit SLES 11. Let me know what other information you might need about my system to troubleshoot this. Using the method described for this installation on the Bioconductor website: source(http://bioconductor.org/biocLite.R;) biocLite(globaltest) I get and the following result, which I can't find an reference to on the list archives: biocLite(globaltest) BioC_mirror: 'http://www.bioconductor.org' Using R version 2.14, BiocInstaller version 1.2.1. Installing package(s) 'globaltest' trying URL 'http://www.bioconductor.org/packages/2.9/bioc/src/contrib/globaltest_5.8.1.tar.gz' Content type 'application/x-gzip' length 956376 bytes (933 Kb) opened URL == downloaded 933 Kb * installing *source* package âglobaltestâ ... ** R ** data ** inst ** preparing package for lazy loading Warning in .simpleDuplicateClass(def, prev) : A specification for class âdata.frameOrNULLâ Creating a generic function for âsortâ from package âbaseâ in package âglobaltestâ Creating a generic function for âmodel.matrixâ from package âstatsâ in package âglobaltestâ Creating a generic function for âcoefficientsâ from package âstatsâ in package âglobaltestâ Creating a generic function for âfitted.valuesâ from package âstatsâ in package âglobaltestâ Creating a generic function for âresidualsâ from package âstatsâ in package âglobaltestâ Error in setMethod(combine, signature(x = gt.result, y = gt.result), : no existing definition for function âcombineâ Error : unable to load R code in package âglobaltestâ ERROR: lazy loading failed for package âglobaltestâ * removing â/usr/local/R-2.14.0/lib64/R/library/globaltestâ The downloaded packages are in â/tmp/RtmpdCwjNB/downloaded_packagesâ Updating HTML index of packages in '.Library' Making packages.html ... done Old packages: 'caret' Update all/some/none? [a/s/n]: Information in this e-mail may be confidential. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this e-mail in error, please notify the sender of the error. [[alternative HTML version deleted]] Information in this e-mail may be confidential. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this e-mail in error, please notify the sender of the error. __ 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 '$' sign?
Hello, Try gsub([$,], , $232,685.35436) Hope this helps, Rui Barradas Em 28-03-2013 15:39, Christofer Bogaso escreveu: Hello again, I want to remove $ sign and replace with nothing in my text. Therefore I used following code: gsub($|,, , $232,685.35436) [1] $232685.35436 However I could not remove '$' sign. Can somebody help me why is it so? Thanks and regards __ 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] bayesian HLM random effects/ problem with base package
my data was deleted, i supposed i uploaded it wrong. that's fine i found the problem... it's with the base package, actually. please see below: R version 2.15.3 (2013-03-01) -- Security Blanket Copyright (C) 2013 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-apple-darwin9.8.0/i386 (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or '()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [R.app GUI 1.53 (6451) i386-apple-darwin9.8.0] [History restored from /Users/nicoleford/.Rhistory] library(car) Loading required package: MASS Loading required package: nnet library(foreign) install.packages(base) --- Please select a CRAN mirror for use in this session --- Warning message: package ‘base’ is not available (for R version 2.15.3) library(base) it is odd because everything was workign just fine yesterday. the rest of my code below and i stop at the problem. --- options(useFancyQuotes=F) dat - read.dta(file.choose()) tmp - rep(NA, nrow(dat)) tmp[which(dat$v128 == no trust at all dat$v127 == no trust at all)] - other tmp[which(dat$v128 == not very much dat$v127 == no trust at all)] - other tmp[which(dat$v128 == somewhat dat$v127 == no trust at all)] - other tmp[which(dat$v128 == trust completely dat$v127 == no trust at all)] - particular tmp[which(dat$v128 == no trust at all dat$v127 == not very much)] - other tmp[which(dat$v128 == not very much dat$v127 == not very much)] - other tmp[which(dat$v128 == somewhat dat$v127 == not very much)] - other tmp[which(dat$v128 == trust completely dat$v127 == not very much)] - particular tmp[which(dat$v128 == no trust at all dat$v127 == somewhat)] - particular tmp[which(dat$v128 == not very much dat$v127 == somewhat)] - particular tmp[which(dat$v128 == somewhat dat$v127 == somewhat)] - particular tmp[which(dat$v128 == trust completely dat$v127 == somewhat)] - particular tmp[which(dat$v128 == no trust at all dat$v127 == trust completely)] - particular tmp[which(dat$v128 == not very much dat$v127 == trust completely)] - particular tmp[which(dat$v128 == somewhat dat$v127 == trust completely)] - particular tmp[which(dat$v128 == trust completely dat$v127 == trust completely)] - generalized tmp - factor(tmp, levels=c(particular, generalized, other)) dat$trust - tmp dat$dem - as.numeric(dat$v162)-5 dat$educ - dat$v238 ls(wvsAB) [1] agecountrycpidemdiversity educ gender income [9] netnumcountry trust clearly, 'uncountry' is not here, and it should be. dat$income - dat$v253 dat$age - dat$v237 dat$gender - dat$v235 dat$country - dat$v2 dat$net - as.factor(as.character(dat$v228)) dat$diversity - as.numeric(dat$v221)-5 wvsA - na.omit(dat[,c(trust, dem, gender, educ, income, age, country, net, diversity)]) # dat - read.dta(file.choose()) tmp - rep(NA, nrow(dat)) tmp[which(dat$v128 == no trust at all dat$v127 == no trust at all)] - other tmp[which(dat$v128 == not very much dat$v127 == no trust at all)] - other tmp[which(dat$v128 == somewhat dat$v127 == no trust at all)] - other tmp[which(dat$v128 == trust completely dat$v127 == no trust at all)] - particular tmp[which(dat$v128 == no trust at all dat$v127 == not very much)] - other tmp[which(dat$v128 == not very much dat$v127 == not very much)] - other tmp[which(dat$v128 == somewhat dat$v127 == not very much)] - other tmp[which(dat$v128 == trust completely dat$v127 == not very much)] - particular tmp[which(dat$v128 == no trust at all dat$v127 == somewhat)] - particular tmp[which(dat$v128 == not very much dat$v127 == somewhat)] - particular tmp[which(dat$v128 == somewhat dat$v127 == somewhat)] - particular tmp[which(dat$v128 == trust completely dat$v127 == somewhat)] - particular tmp[which(dat$v128 == no trust at all dat$v127 == trust completely)] - particular tmp[which(dat$v128 == not very much dat$v127 == trust completely)] - particular tmp[which(dat$v128 == somewhat dat$v127 == trust completely)] - particular tmp[which(dat$v128 == trust completely dat$v127 == trust completely)] - generalized tmp - factor(tmp, levels=c(particular, generalized, other)) dat$trust - tmp dat$dem - as.numeric(dat$v162)-5 dat$educ - dat$v238 dat$income - dat$v253 dat$age - dat$v237 dat$gender - dat$v235 dat$country - dat$v2 dat$net - as.factor(as.character(dat$v228))
Re: [R] bayesian HLM random effects
right i am sorry. i am working in the dput() now. ~Nicole Ford Ph.D. student Graduate Assistant/ Instructor University of South Florida Government and International Affairs office: SOC 012M On Mar 28, 2013, at 12:01 PM, Sarah Goslee wrote: Key words being small reproducible example - see http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example I find it hard to believe that unique() has quit working, but it's impossible to figure out what's going on without more context. And don't forget that you need to hit Reply all to send messages to the list rather than to just me. On Thu, Mar 28, 2013 at 11:59 AM, Nicole Ford nicolefor...@gmail.com wrote: oh i misread your post. i will look into dput. for data. On Mar 28, 2013, at 11:53 AM, Sarah Goslee wrote: Nicole, this list strips binary attachments. Using dput() is the most effective way to include some of your data, and we also need to see the R code you're trying to use, and some information about what you want to accomplish, all included in the body of your email. Sarah On Thu, Mar 28, 2013 at 9:48 AM, Nicole Ford nicole.f...@me.com wrote: Hello, all. I've been working on this for sometime and was almost at the end/ last chunk of code i would need When I received an error. Rather than go to bed and think about it in the morning, I messed with my data and now I am not getting anything. I was up until 4am trying to fix this. Zip files of my data are attached (the data which ends in 'a' matches with wvsA and the data which ends in 'b' matches with my data code wvsB). my code is below. I can't even get plots, now. If i can just get to that point, i would be eternally grateful for any help. please find my code attached, as well. - -- Sarah Goslee http://www.functionaldiversity.org [[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] unique not working
Now R isn't running on my computer AT ALL. i deleted it and d/l'd again, trying to get it to work, it keeps crashing. so perhaps this is a hardware issue. the absolute worst timing. ~Nicole Ford Ph.D. Student Instructor: Empirical Political Analysis Department of Government and International Affairs University of South Florida Office: SOC 012M On Thu, Mar 28, 2013 at 1:30 PM, Nicole Ford nicolefor...@gmail.com wrote: i meant uncountry. i am creating one now/ dput(). thanks. ~Nicole Ford Ph.D. student Graduate Assistant/ Instructor University of South Florida Government and International Affairs office: SOC 012M On Mar 28, 2013, at 11:55 AM, Sarah Goslee wrote: Hi, I'm confused. On Thu, Mar 28, 2013 at 10:49 AM, Nicole Ford nicolefor...@gmail.com wrote: i am using mac OSX 10.7.5, running R version 2.15.2 (2012-10-26) -- Trick or Treat when i do: uncountry - unique(wvsAB[,7]) wvsAB$numcountry - match(wvsAB$country, uncountry) unstate isn't attaching. What's unstate? What does isn't attaching mean? Why don't you provide a sample of your data with dput() and tell us what you're trying to accomplish so we can help. library(base) uncountry - unique(wvsAB[,7]) wvsAB$numcountry - match(wvsAB$country, uncountry) ls(wvsAB) [1] agecountrycpidemdiversity educ gender income [9] netnumcountry trust thanks in advance for any help. -- Sarah Goslee http://www.functionaldiversity.org [[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] Odd graphic device behavior
Thomas, any chance that you could have problems with your graphic driver? For instance, if you have an Nvidia graphic card, I would recommend switching from the 'nouveau' driver to the official Nvidia one. Kind regards, luca [[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] bayesian HLM random effects
I have several plots from attempts yesterday where i was clearly getting the data in. however, that is no longer the case. ~Nicole Ford Ph.D. student Graduate Assistant/ Instructor University of South Florida Government and International Affairs office: SOC 012M On Mar 28, 2013, at 12:01 PM, Sarah Goslee wrote: Key words being small reproducible example - see http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example I find it hard to believe that unique() has quit working, but it's impossible to figure out what's going on without more context. And don't forget that you need to hit Reply all to send messages to the list rather than to just me. On Thu, Mar 28, 2013 at 11:59 AM, Nicole Ford nicolefor...@gmail.com wrote: oh i misread your post. i will look into dput. for data. On Mar 28, 2013, at 11:53 AM, Sarah Goslee wrote: Nicole, this list strips binary attachments. Using dput() is the most effective way to include some of your data, and we also need to see the R code you're trying to use, and some information about what you want to accomplish, all included in the body of your email. Sarah On Thu, Mar 28, 2013 at 9:48 AM, Nicole Ford nicole.f...@me.com wrote: Hello, all. I've been working on this for sometime and was almost at the end/ last chunk of code i would need When I received an error. Rather than go to bed and think about it in the morning, I messed with my data and now I am not getting anything. I was up until 4am trying to fix this. Zip files of my data are attached (the data which ends in 'a' matches with wvsA and the data which ends in 'b' matches with my data code wvsB). my code is below. I can't even get plots, now. If i can just get to that point, i would be eternally grateful for any help. please find my code attached, as well. - -- Sarah Goslee http://www.functionaldiversity.org [[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] new question
Hi, You also mentioned about separating the significant from the non-significant. If you replace: Chisq1test_Count-do.call(cbind,lapply(as.data.frame(combn(names(res)[4:ncol(res)],2),stringsAsFactors=FALSE),function(x) {x1-data.frame(apply(cbind(res[x[1]],res[x[2]]),1,function(y){ifelse(sum(y)==0, NA, chisq.test(y)$p.value)}));colnames(x1)- paste0(Count_,x[1],x[2]);x1})) res1- cbind(res,Chisq1test_Count) with Chisqtest_CountNew-do.call(cbind,lapply(as.data.frame(combn(names(res)[4:ncol(res)],2),stringsAsFactors=FALSE),function(x) {x1-data.frame(apply(cbind(res[x[1]],res[x[2]]),1,function(y){ifelse(sum(y)==0, NA, chisq.test(y)$p.value)}));colnames(x1)- paste0(Count_,x[1],x[2]);x2-within(x1,{Flag-ifelse(x1[,1]0.05,S,NS)}); colnames(x2)[2]-paste0(colnames(x2)[1],_Flag);x2})) res1- cbind(res,Chisqtest_CountNew) in the Spec(), head(Spec(ListFacGroup,0.05),2) # Seq Mod z a2 c2 c3 t2 V1.Count_a2c2 #1 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 0.02534732 #2 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 0.01430588 # V1.Count_a2c2_Flag V2.Count_a2c3 V2.Count_a2c3_Flag V3.Count_a2t2 #1 S 0.02534732 S 0.10247043 #2 S 0.01430588 S 0.05878172 # V3.Count_a2t2_Flag V4.Count_c2c3 V4.Count_c2c3_Flag V5.Count_c2t2 #1 NS NA NA 0.3173105 #2 NS NA NA 0.3173105 # V5.Count_c2t2_Flag V6.Count_c3t2 V6.Count_c3t2_Flag #1 NS 0.3173105 NS #2 NS 0.3173105 NS A.K. - Original Message - From: arun smartpink...@yahoo.com To: Vera Costa veracosta...@gmail.com Cc: R help r-help@r-project.org Sent: Thursday, March 28, 2013 2:28 PM Subject: Re: [R] new question Hi, The function outputs the unique rows and also chisq test on frequency ( by row). Spec - function(lista,FDR_k) { list.new-lapply(lista,function(x) within(x,{spec- as.character(spec)})) split.list-split(list.new,names(lista)) #Data needed with FDRFDR_k seq.mod.z-lapply(seq_along(split.list),function(i) lapply(split.list[[i]],function(x) x[x[[FDR]]FDR_k,c(Seq,Mod,z,spec)])) names(seq.mod.z)- names(split.list) #insert colunm with the name of the folder folder.name-lapply(seq.mod.z,function(x) lapply(names(x),function(i) do.call(rbind,lapply(x[i],function(x) cbind(folder_name=i,x) #merge data with the same Seq, Mod and z library(plyr) library(data.table) merge.data- lapply(folder.name,function(x) lapply(x,function(x1) {x1-data.table(x1); x1[,spec:=paste(spec,collapse=,),by=c(Seq,Mod,z)]})) #colunm with number of spec count.spec-lapply(merge.data,function(x) lapply(x,function(x1) {x1$counts-sapply(x1$spec, function(x2) length(gsub(\\s, , unlist(strsplit(x2, ,);x3-as.data.frame(x1);names(x3)[6]- as.character(unique(x3$folder_name));x3[,-c(1,5)]})) count.specUnique-lapply(count.spec,function(x) lapply(x,unique)) #count spec by group (2-columns) spec.group-lapply(count.specUnique,function(x) Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),x)) #spec.group1-spec.group[lapply(spec.group,length)!=0] #data frame with count of spec res- Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),spec.group) res[is.na(res)] - 0 res- as.data.frame(res,stringsAsFactors=FALSE) #print(res) Chisq1test_Count-do.call(cbind,lapply(as.data.frame(combn(names(res)[4:ncol(res)],2),stringsAsFactors=FALSE),function(x) {x1-data.frame(apply(cbind(res[x[1]],res[x[2]]),1,function(y){ifelse(sum(y)==0, NA, chisq.test(y)$p.value)}));colnames(x1)- paste0(Count_,x[1],x[2]);x1})) #print(Chisq1test_Count) res1- cbind(res,Chisq1test_Count) res1 } ListFacGroup-ReadDir(FacGroup) Spec(ListFacGroup,0.05) head(Spec(ListFacGroup,0.05)) # Seq Mod z a2 c2 c3 t2 Count_a2c2 #1 aAATATAGPR 1-n_acPro/ 2 5 0 0 1 0.02534732 #2 aAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1 0.01430588 #3 aAGAAGGR 1-n_acPro/ 2 1 1 0 1 1. #4 AAALQAK 2 1 0 1 1 0.31731051 #5 aAGAGPEMVR 1-n_acPro/ 2 2 2 1 2 1. #6 aEQQQFYLLLGNLLSPDNVVR 1-_Carbamoylation/ 2 1 0 0 1 0.31731051 # Count_a2c3 Count_a2t2 Count_c2c3 Count_c2t2 Count_c3t2 #1 0.02534732 0.10247043 NA 0.3173105 0.3173105 #2 0.01430588 0.05878172 NA 0.3173105 0.3173105 #3 0.31731051 1. 0.3173105 1.000 0.3173105 #4 1. 1. 0.3173105 0.3173105 1.000 #5 0.56370286 1. 0.5637029 1.000 0.5637029 #6 0.31731051 1. NA 0.3173105 0.3173105 A.K. From: arun smartpink...@yahoo.com To: Vera Costa veracosta...@gmail.com Cc: R help r-help@r-project.org Sent: Thursday, March 28, 2013 10:18 AM Subject: Re: [R] new question Hi, Try
Re: [R] unique not working
i meant uncountry. i am creating one now/ dput(). thanks. ~Nicole Ford Ph.D. student Graduate Assistant/ Instructor University of South Florida Government and International Affairs office: SOC 012M On Mar 28, 2013, at 11:55 AM, Sarah Goslee wrote: Hi, I'm confused. On Thu, Mar 28, 2013 at 10:49 AM, Nicole Ford nicolefor...@gmail.com wrote: i am using mac OSX 10.7.5, running R version 2.15.2 (2012-10-26) -- Trick or Treat when i do: uncountry - unique(wvsAB[,7]) wvsAB$numcountry - match(wvsAB$country, uncountry) unstate isn't attaching. What's unstate? What does isn't attaching mean? Why don't you provide a sample of your data with dput() and tell us what you're trying to accomplish so we can help. library(base) uncountry - unique(wvsAB[,7]) wvsAB$numcountry - match(wvsAB$country, uncountry) ls(wvsAB) [1] agecountrycpidemdiversity educ gender income [9] netnumcountry trust thanks in advance for any help. -- Sarah Goslee http://www.functionaldiversity.org [[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] Newey West HAC for pooled cross-section data
Many thanks. On Wed, Mar 27, 2013 at 3:50 AM, Achim Zeileis-4 [via R] ml-node+s789695n4662592...@n4.nabble.com wrote: On Tue, 26 Mar 2013, SHISHIR MATHUR wrote: Thanks for the reply Achim. The reason I suspect autocorrelation is because I think that within the same neighborhood, homes sold a few months back are likely to impact the price of homes sold subsequently. This may well be spatial (auto)correlation rather than temporal autocorrelation. In fact the DW test and Breusch-Pagan test come out to be significant. So even though the data is not time series (that is, I do not have repeated observations for the same house), however, the houses sold close in time to each other are in the data set. If there is a unique ordering of all observations by time, then you could in principle apply an autocorrelation correction for the data, e.g., via Newey-West. But from what you describe above, it seems to be more important to capture spatial effects in the data, e.g., by using a spatial lag model (see lagsarlm in spdep) or by using an additive spatial effect (see e.g. gam in mgcv). Thanks, Shish On Tue, Mar 26, 2013 at 3:51 PM, Achim Zeileis [hidden email]http://user/SendEmail.jtp?type=nodenode=4662592i=0 wrote: On Tue, 26 Mar 2013, SHISHIR MATHUR wrote: Hello: My dataset set contains several thousand rows of data, with each row containing information for a house. The variables include the sale price of the house, the quarter and year of sale, the attributes of the house, and the attributes of the neighborhood and the city in which the house is located. The data is for a 10-year period. No house is repeated in the dataset. In summary, the dataset can be termed pooled cross-section data. My question: Can I estimate Newey-West HAC standard errors for a model that estimates the effect of various independent variables on the sale price of the house? My understanding is that Newey-West can be used for time series and panel data. However, I am not sure whether it can be used for pooled cross-section data. If yes, can you refer me to a specific source, such as a paper or a book? The result of your aggregation is a cross-section data set. Thus, there should be no correlation between the different observations - or in other terms, the ordering of your observations is completely arbitrary. Consequently, there may be heteroskedasticity but not autocorrelation. So you may use HC standard errors but HAC should not be necessary. (Using HAC standard errors will still be consistent but less efficient.) -- Best, Shish [[alternative HTML version deleted]] __ [hidden email]http://user/SendEmail.jtp?type=nodenode=4662592i=1mailing 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. -- Best, Shishir __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4662592i=2mailing 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. -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Newey-West-HAC-for-pooled-cross-section-data-tp4662563p4662592.html To unsubscribe from Newey West HAC for pooled cross-section data, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4662563code=bWF0aHVyc2hpc2hpcjFAZ21haWwuY29tfDQ2NjI1NjN8NDY0NTY1ODMx . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- Best, Shishir -- View this message in context: http://r.789695.n4.nabble.com/Newey-West-HAC-for-pooled-cross-section-data-tp4662563p4662760.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Re: [R] Error in setMethod(combine... was - Error when installing globaltest package
On 3/28/2013 11:05 AM, Shields, Rusty (IMS) wrote: Hi All, I posted this on the bioconductor list and didn't get a response there, so I'm hoping someone here can help. I don't know a heck of a lot about R, so I apologize if this seems like a trivial issue. This error comes up when trying to install the bioconductor globaltest package. Sorry that you didn't get a response on the Bioc mailing list; I'd actually suggest returning to the original thread there and I'll see that it gets answered. My guess is that you have a version of Biobase that is too new compared to the version (2.14.0) expected in the version of Bioconductor you are using. What does packageDescription(Biobase) say? Martin Any clues? Thanks! Rusty -Original Message- From: bioconductor-boun...@r-project.org [mailto:bioconductor-boun...@r-project.org] On Behalf Of Shields, Rusty (IMS) Sent: Tuesday, March 26, 2013 12:34 PM To: bioconduc...@r-project.org Subject: [BioC] Error when installing globaltest package Hi all, I've run into a problem when attempting to install the globaltest package from Bioconductor. I'm using R 2.14.0 on 64bit SLES 11. Let me know what other information you might need about my system to troubleshoot this. Using the method described for this installation on the Bioconductor website: source(http://bioconductor.org/biocLite.R;) biocLite(globaltest) I get and the following result, which I can't find an reference to on the list archives: biocLite(globaltest) BioC_mirror: 'http://www.bioconductor.org' Using R version 2.14, BiocInstaller version 1.2.1. Installing package(s) 'globaltest' trying URL 'http://www.bioconductor.org/packages/2.9/bioc/src/contrib/globaltest_5.8.1.tar.gz' Content type 'application/x-gzip' length 956376 bytes (933 Kb) opened URL == downloaded 933 Kb * installing *source* package âglobaltestâ ... ** R ** data ** inst ** preparing package for lazy loading Warning in .simpleDuplicateClass(def, prev) : A specification for class âdata.frameOrNULLâ Creating a generic function for âsortâ from package âbaseâ in package âglobaltestâ Creating a generic function for âmodel.matrixâ from package âstatsâ in package âglobaltestâ Creating a generic function for âcoefficientsâ from package âstatsâ in package âglobaltestâ Creating a generic function for âfitted.valuesâ from package âstatsâ in package âglobaltestâ Creating a generic function for âresidualsâ from package âstatsâ in package âglobaltestâ Error in setMethod(combine, signature(x = gt.result, y = gt.result), : no existing definition for function âcombineâ Error : unable to load R code in package âglobaltestâ ERROR: lazy loading failed for package âglobaltestâ * removing â/usr/local/R-2.14.0/lib64/R/library/globaltestâ The downloaded packages are in â/tmp/RtmpdCwjNB/downloaded_packagesâ Updating HTML index of packages in '.Library' Making packages.html ... done Old packages: 'caret' Update all/some/none? [a/s/n]: Information in this e-mail may be confidential. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this e-mail in error, please notify the sender of the error. [[alternative HTML version deleted]] Information in this e-mail may be confidential. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this e-mail in error, please notify the sender of the error. __ 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. -- Dr. Martin Morgan, PhD Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 __ 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] QUESTION ON ROUNDING
On 28/03/2013 2:21 PM, Andras Farkas wrote: Dear All, wonder if you have a thought on the following: I am using the round(x,digits=3) command, but some of my values come out as: 0.07099 AND 0.06901. Any thoughts on why this maty be happening or how to eliminate the problem? You are confusing rounding and string conversion. I imagine 0.07099 is what you get when you print 0.071 with 17 digits, because 0.071 can't be represented exactly in the double precision floating point that R uses. If you want to format it for display, then use format() (or sprintf(), or one of the other formatting functions), don't use round(). Duncan Murdoch __ 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] Odd graphic device behavior
Luca, Thank you for the suggestion; I do have an Nvidia graphics card and I am using the Nvida driver; still searching for a solution, quite odd... Tom On Thu, Mar 28, 2013 at 12:28 PM, Luca Nanetti luca.nane...@gmail.comwrote: Thomas, any chance that you could have problems with your graphic driver? For instance, if you have an Nvidia graphic card, I would recommend switching from the 'nouveau' driver to the official Nvidia one. Kind regards, luca [[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] animated charts
The tkexamp function in the TeachingDemos package has an animation control that you can use. The animation package will create video files of animated graphs. On Wed, Mar 27, 2013 at 7:20 AM, catalin roibu catalinro...@gmail.comwrote: Hello all! I want to create animated chart of temperature variation in last century. how can I do this with R? Thank you! -- --- Catalin-Constantin ROIBU Forestry engineer, PhD Forestry Faculty of Suceava Str. Universitatii no. 13, Suceava, 720229, Romania office phone +4 0230 52 29 78, ext. 531 mobile phone +4 0745 53 18 01 +4 0766 71 76 58 FAX:+4 0230 52 16 64 silvic.usv.ro [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[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] using cvlm to do cross-validation
Hello, I did a cross-validation using cvlm from DAAG package but wasn't sure how to assess the result. Does this result means my model is a good model? I understand that the overall ms is the mean of sum of squares. But is 0.0987 a good number? The response (i.e. gailRel5yr) has min,1st Quantile, median, mean and 3rd Quantile, and max as follows: (0.462, 0.628, 0.806, 0.896, 1.000, 2.400) The plot generated by cvlm, the point does not look too tight. Thanks in advance CVlm(gailRel5yr~risk.sum,m=10) Analysis of Variance Table Response: gailRel5yr Df Sum Sq Mean Sq F value Pr(F) risk.sum 1 4.19 4.19 44.8 2e-09 *** Residuals 88 8.24 0.09 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 fold 1 Observations in test set: 9 3 7 17 27 46 66 67 83 89 risk.sum 27.2345 66.447 29.20988 33.806 28.861 20.293 29.210 1.883 12.482 cvpred 0.9693 1.607 1.00148 1.076 0.996 0.856 1.001 0.557 0.729 gailRel5yr 1. 1.333 1.0 0.778 0.667 1.000 0.750 0.727 1.000 CV residual 0.0307 -0.274 -0.00148 -0.298 -0.329 0.144 -0.251 0.170 0.271 Sum of squares = 0.46 Mean square = 0.05 n = 9 fold 2 Observations in test set: 9 5 41 42 49 51 64 69 81 84 risk.sum 28.529 24.779 28.529 16.194 47.222 8.383 5.813 1.8832 16.1937 cvpred 0.975 0.922 0.975 0.800 1.241 0.688 0.652 0.5958 0.7996 gailRel5yr 0.625 0.533 1.143 0.636 1.833 0.462 1.000 0.5385 0.7143 CV residual -0.350 -0.389 0.168 -0.163 0.592 -0.227 0.348 -0.0573 -0.0853 Sum of squares = 0.86 Mean square = 0.1 n = 9 fold 3 Observations in test set: 9 2 8 12 25 30 47 56 74 82 risk.sum 24.043 12.5825 10.969 16.803 29.017 49.341 15.455 28.256 21.906 cvpred 0.925 0.7651 0.743 0.824 0.995 1.279 0.805 0.984 0.896 gailRel5yr 0.545 0.6923 0.571 0.500 0.714 1.857 0.714 0.667 0.500 CV residual -0.380 -0.0728 -0.171 -0.324 -0.281 0.578 -0.091 -0.318 -0.396 Sum of squares = 0.96 Mean square = 0.11 n = 9 fold 4 Observations in test set: 9 16 22 26 44 50 61 71 72 79 risk.sum 32.960 44.11 17.1 32.628 16.194 5.9823 5.9823 21.955 21.168 cvpred 1.030 1.19 0.8 1.025 0.786 0.6379 0.6379 0.870 0.858 gailRel5yr 1.667 1.57 1.0 0.500 1.000 0.6000 0.6000 0.625 1.143 CV residual 0.637 0.38 0.2 -0.525 0.214 -0.0379 -0.0379 -0.245 0.284 Sum of squares = 1.06 Mean square = 0.12 n = 9 fold 5 Observations in test set: 9 13 15 37 40 48 59 62 76 78 risk.sum 5.8134 28.5287 28.5287 5.982 29.766 45.754 10.468 28.878 1.883 cvpred 0.6144 0.9569 0.9569 0.617 0.976 1.217 0.685 0.962 0.555 gailRel5yr 0.6667 1. 1. 1.000 0.875 1.833 0.933 1.214 0.909 CV residual 0.0523 0.0431 0.0431 0.383 -0.101 0.617 0.249 0.252 0.354 Sum of squares = 0.79 Mean square = 0.09 n = 9 fold 6 Observations in test set: 9 19 32 33 55 57 68 80 86 88 risk.sum 14.719 28.529 24.043 10.468 20.293 12.48 1.883 5.813 5.982 cvpred 0.764 0.980 0.910 0.698 0.852 0.73 0.564 0.625 0.628 gailRel5yr 1.000 0.667 0.667 0.538 0.667 1.00 0.778 1.000 0.500 CV residual 0.236 -0.314 -0.243 -0.160 -0.185 0.27 0.214 0.375 -0.128 Sum of squares = 0.55 Mean square = 0.06 n = 9 fold 7 Observations in test set: 9 20 24 36 45 52 63 65 87 90 risk.sum 35.3605 10.620 26.44 5.9823 29.766 31.074 16.194 20.293 1.883 cvpred 1.0896 0.702 0.95 0.6289 1.002 1.022 0.789 0.853 0.565 gailRel5yr 1. 1.000 0.50 0.6000 1.143 0.714 0.600 1.000 0.933 CV residual -0.0896 0.298 -0.45 -0.0289 0.141 -0.308 -0.189 0.147 0.369 Sum of squares = 0.61 Mean square = 0.07 n = 9 fold 8 Observations in test set: 9 18 21 23 28 38 70 73 75 77 risk.sum 25.656 26.239 49.353 16.682 9.7323 6.870 1.883 1.883 20.293 cvpred 0.943 0.953 1.337 0.794 0.6782 0.631 0.548 0.548 0.854 gailRel5yr 0.700 0.929 0.667 1.000 0.7500 0.944 0.667 0.778 0.462 CV residual -0.243 -0.024 -0.670 0.206 0.0718 0.314 0.119 0.230 -0.392 Sum of squares = 0.88 Mean square = 0.1 n = 9 fold 9 Observations in test set: 9 6 9 34 35 39 43 54 60 85 risk.sum 46.480 29.030 16.19369 40.364 14.7192 17.826 17.8264 26.588 16.194 cvpred 1.241 0.985 0.79725 1.151 0.7757 0.821 0.8212 0.950 0.797 gailRel5yr 1.667 0.846 0.8 1.000 0.8125 1.083 0.8333 0.556 0.533 CV residual 0.426 -0.139 0.00275 -0.151 0.0368 0.262 0.0122 -0.394 -0.264 Sum of squares = 0.52 Mean square = 0.06 n = 9 fold 10
[R] ggplot2: less than equal sign
Hi I am trying to add a less than equal sign to a plot. I have previously done this using unicode but is not working in this instance. Any suggestions would be great thanks example code: library(ggplot2) df-data.frame(vis=c(0,0,1,1) , count=c(10,15,20,10) , grp=c(0,1,0,1)) df$grp -factor(df$grp ,levels=c(0,1) , labels =c(x \u2265 10 , x 10)) ggplot(df, aes(x = factor(vis), y=count , fill=grp)) + geom_bar(stat = identity) -- View this message in context: http://r.789695.n4.nabble.com/ggplot2-less-than-equal-sign-tp4662784.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] Odd graphic device behavior
All, Well to my relief and embarrassment, I discovered my problem. About 5 weeks ago, I shutdown my computer and moved it. When I reconnected everything I apparently plugged my HDMI monitor into the 'wrong' output port without realizing it. So, on a whim, just now, I made the switch to the other port and presto changeo -- problem solved!! The odd thing was, besides my R graphics device window problems, everything else was fine... Out of curiosity, can anyone explain this? Thanks for all the help... Tom On Thu, Mar 28, 2013 at 4:06 PM, Thomas Adams tea...@gmail.com wrote: Luca, Thank you for the suggestion; I do have an Nvidia graphics card and I am using the Nvida driver; still searching for a solution, quite odd... Tom On Thu, Mar 28, 2013 at 12:28 PM, Luca Nanetti luca.nane...@gmail.comwrote: Thomas, any chance that you could have problems with your graphic driver? For instance, if you have an Nvidia graphic card, I would recommend switching from the 'nouveau' driver to the official Nvidia one. Kind regards, luca [[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] ggplot2: less than equal sign
Hi, If you want to stick with the unicode way make sure to set your encoding system, e.g., on Mac Sys.setlocale(LC_ALL, en_US.UTF-8) This differs on Windows/Linux so see ?Sys.setlocale for examples on other platforms. Best, Ista On Thu, Mar 28, 2013 at 5:22 PM, soon yi soon...@ymail.com wrote: Hi I am trying to add a less than equal sign to a plot. I have previously done this using unicode but is not working in this instance. Any suggestions would be great thanks example code: library(ggplot2) df-data.frame(vis=c(0,0,1,1) , count=c(10,15,20,10) , grp=c(0,1,0,1)) df$grp -factor(df$grp ,levels=c(0,1) , labels =c(x \u2265 10 , x 10)) ggplot(df, aes(x = factor(vis), y=count , fill=grp)) + geom_bar(stat = identity) -- View this message in context: http://r.789695.n4.nabble.com/ggplot2-less-than-equal-sign-tp4662784.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.
Re: [R] ggplot2: less than equal sign
Hi: Here's a way you could do it entirely within ggplot2. The annotation functions have a parse = argument which allows you to pass character string representations of math expressions, but there is no such thing in the scale functions, so you need a different approach. library(ggplot2) df - data.frame(vis=c(0,0,1,1) , count=c(10,15,20,10) , grp=c(0,1,0,1)) # Generate a list of expressions that will become the legend labels lbs - list(expression(x = 10), expression(x 10)) ggplot(df, aes(x = factor(vis), y=count , fill=factor(grp))) + geom_bar(stat =identity) + scale_fill_manual(breaks = levels(factor(df$grp)), values = c(blue, orange), labels = lbs) The specifications in scale_fill_manual() are: - breaks: the values to go on the horizontal axis - values: the vector of fill colors for each level of grp - labels: the legend labels Notice that the labels = takes a list of expressions as its argument. This approach gives you more control over the legend and choice of fill colors at the expense of a couple of lines of code. To change the axis and legend titles, one can use the labs() function; e.g., last_plot() + labs(x = Visibility, y = Frequency, fill = Threshold) Dennis On Thu, Mar 28, 2013 at 2:22 PM, soon yi soon...@ymail.com wrote: Hi I am trying to add a less than equal sign to a plot. I have previously done this using unicode but is not working in this instance. Any suggestions would be great thanks example code: library(ggplot2) df-data.frame(vis=c(0,0,1,1) , count=c(10,15,20,10) , grp=c(0,1,0,1)) df$grp -factor(df$grp ,levels=c(0,1) , labels =c(x \u2265 10 , x 10)) ggplot(df, aes(x = factor(vis), y=count , fill=grp)) + geom_bar(stat = identity) -- View this message in context: http://r.789695.n4.nabble.com/ggplot2-less-than-equal-sign-tp4662784.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] hierarchical clustering with pearson's coefficient
Hello, I want to use pearson's correlation as distance between observations and then use any centroid based linkage distance (ex. Ward's distance) When linkage distances are formed as the Lance-Williams recursive formulation, they just require the initial distance between observations. See here: http://en.wikipedia.org/wiki/Ward%27s_method It is said that you have to use euclidean distance between the initial observations. However i have found this: http://research.stowers-institute.org/efg/R/Visualization/cor-cluster/ where they use pearson's correlation for hierarchical clustering. Any idea if anything is violated in case pearson's correlation is used with Ward's linkage function? the dissimilarity of pearson's correlation can be defined as d = sqrt(1-pearsonsimilarity^2). can that be considered as norm1 distance? and thus norm2 if we square it? so that the wikipedia's statement To apply a recursive algorithm under this objective function, the initial distance between individual objects must be (proportional to) squared Euclidean distance. is valid? Best, Pierre [[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] ggplot2: less than equal sign
Thank you both for the suggestions. That worked great djmuse. djmuseR wrote Hi: Here's a way you could do it entirely within ggplot2. The annotation functions have a parse = argument which allows you to pass character string representations of math expressions, but there is no such thing in the scale functions, so you need a different approach. library(ggplot2) df - data.frame(vis=c(0,0,1,1) , count=c(10,15,20,10) , grp=c(0,1,0,1)) # Generate a list of expressions that will become the legend labels lbs - list(expression(x = 10), expression(x 10)) ggplot(df, aes(x = factor(vis), y=count , fill=factor(grp))) + geom_bar(stat =identity) + scale_fill_manual(breaks = levels(factor(df$grp)), values = c(blue, orange), labels = lbs) The specifications in scale_fill_manual() are: - breaks: the values to go on the horizontal axis - values: the vector of fill colors for each level of grp - labels: the legend labels Notice that the labels = takes a list of expressions as its argument. This approach gives you more control over the legend and choice of fill colors at the expense of a couple of lines of code. To change the axis and legend titles, one can use the labs() function; e.g., last_plot() + labs(x = Visibility, y = Frequency, fill = Threshold) Dennis On Thu, Mar 28, 2013 at 2:22 PM, soon yi lt; soon.yi@ gt; wrote: Hi I am trying to add a less than equal sign to a plot. I have previously done this using unicode but is not working in this instance. Any suggestions would be great thanks example code: library(ggplot2) df-data.frame(vis=c(0,0,1,1) , count=c(10,15,20,10) , grp=c(0,1,0,1)) df$grp -factor(df$grp ,levels=c(0,1) , labels =c(x \u2265 10 , x 10)) ggplot(df, aes(x = factor(vis), y=count , fill=grp)) + geom_bar(stat = identity) -- View this message in context: http://r.789695.n4.nabble.com/ggplot2-less-than-equal-sign-tp4662784.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/ggplot2-less-than-equal-sign-tp4662784p4662789.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] Summer Statistics Institute at UT Austin, May 20-23, 2013
The Division of Statistics + Scientific Computation at The University of Texas at Austin will be hosting the University’s sixth annual UT Summer Statistics Institute on the UT Austin campus from May 20 – May 23, 2013. Short courses are offered at all levels including introductory statistics, software, and statistical methods and applications. We are offering Introduction to R, Multivariate Data Analysis Using R, Introduction to Data Mining, Advanced Regression, Applied Text-Mining and Text-Analysis Using R, and Power Analysis for Proposal Writing, which all use R, as well as other courses that would be of interest to R users. Learn the statistics you’ve always wanted to know from some of the very finest faculty at UT! Registration closes May 3. Students receive a 60% discount and groups can receive a 20% discount off the regular $550 course fee. Visit our website at http://ssc.utexas.edu/programs/summer-statistics-institute to download the UT Summer Statistics Institute brochure and learn more. Short courses are offered at all levels including introductory statistics, software, and statistical methods and applications. New this year: *Applied Text-Mining and Text-Analysis with R *Introduction to Visual Analytics *Pattern Analysis, Predictive Analytics and Big Data: Theory and Methods *A Unifying Statistical Framework for Big Data: Graphical Models *Introduction to MapReduce Programming Model with Hadoop *Writing Competitive Federal Grant Proposals We are offering these introductory courses in common statistical software: *Introduction to Microsoft Access *Introduction to R *Introduction to Stata [sponsored by www.stata.com] *Introduction to SPSS *Data Analysis Using SAS - Michael J. Mahometa, Ph.D. Manager, Consulting Services Division of Statistics and Scientific Computation College of Natural Sciences - G2500 University of Texas at Austin 512.471.4542 __ 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] Crrstep help
Hi Kathy, You should first contact the package maintainer (which is me!) before posting to r-help. Which version of the package are you using? Can you send me a minimally reproducible code? Ravi Ravi Varadhan, Ph.D. Assistant Professor The Center on Aging and Health Division of Geriatric Medicine Gerontology Johns Hopkins University rvarad...@jhmi.edumailto:rvarad...@jhmi.edu 410-502-2619 [[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] Crrstep help
Kathy, You need to make sure that you have installed the latest version of `cmprsk' package (version 2.2-4). crrstep will not work Otherwise. Ravi From: Ravi Varadhan Sent: Thursday, March 28, 2013 5:25 PM To: 'kathyhan...@gmail.com' Cc: r-help@r-project.org Subject: Re: [R] Crrstep help Hi Kathy, You should first contact the package maintainer (which is me!) before posting to r-help. Which version of the package are you using? Can you send me a minimally reproducible code? Ravi Ravi Varadhan, Ph.D. Assistant Professor The Center on Aging and Health Division of Geriatric Medicine Gerontology Johns Hopkins University rvarad...@jhmi.edumailto:rvarad...@jhmi.edu 410-502-2619 [[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] Need to read an Excel File
To be able to import excel-files into R you also need to download Perl from http://www.perl.org/. From this link you will have to downlaod a suitable Strawberry based on the computer you use (Mac/Window). Once installed you should be able to move on. -- View this message in context: http://r.789695.n4.nabble.com/Need-to-read-an-Excel-File-tp2307915p4662778.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 partimat()
Hello Everyone, I was wondering if anyone knows a solution to a problem I am experiencing. I have an R script that creates multiple graphs of the data in several data file using the partimat() function that is located in the klaR library. I would like to get this graphs into a single image similar to the way one can use the par() function and then the plot() function to put multiple plots side by side. The problem is that the par() function does not work with partimat() so I was wondering if there is an equivalent way of achieving the same result when using partimat(). I have searched for several hours already and I have not been able to find a solution. I would greatly appreciate any help. Attached is the script as well as the end result I would like to get after running the script. Thank you, Antelmo Aguilar__ 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 plots with short example.
i am having problem running my own data. yesterday it was working just fine. today it is not. this is the code i was using as an example to follow. this code ALSO worked just fine yesterday, and is no longer working at all. i suspect it is a problem with either my computer or the software, at this point. if THIS won't even run something is wrong. i can assure you this isn't HW i know dave, but i am no longer at UW-M and i have never learned HLMs and i am learning this on my own for my own research. his code is here, along with data. it is short, quick, etc. http://www.quantoid.net/936/Lecture7.R ### R code from vignette source 'Lecture7.Rnw' ### ### code chunk number 1: opts ### options(useFancyQuotes=F) ### ### code chunk number 2: data1 ### library(foreign) therms - na.omit(read.dta(http://quantoid.net/936/2008_difftherm.dta;)) unstate - unique(therms[,1]) therms$numstate - match(therms$state, unstate) library(runjags) dat - dump.format(list( N = nrow(therms), J=length(unstate), y = therms$difftherm, numstate = therms$numstate )) ### ### code chunk number 3: exchange ### exchange.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu, tau) } mu ~ dnorm(0,.001) tau ~ dgamma(.1,.1) } exchange.out - run.jags(exchange.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 4: exchange ### FE.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(0,.001) tau[j] ~ dgamma(.1,.1) } } FE.out - run.jags(FE.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 5: exchange ### hier.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(theta,nu) tau[j] ~ dgamma(a,b) } theta ~ dnorm(0,.01) nu ~ dgamma(.1,.1) a ~ dunif(0,1000) b ~ dunif(0,1000) } hier.out - run.jags(hier.mod, data=dat, burnin=1, sample=10, thin=10, monitor=c(mu, tau, theta, nu, a, b), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 6: sums ### hier.chains - combine.mcmc(hier.out$mcmc) FE.chains - combine.mcmc(FE.out$mcmc) exchange.chains - combine.mcmc(exchange.out$mcmc) mu.bar - apply(FE.chains[, grep(mu\\[, colnames(FE.chains))], 2, mean) mu.bar2 - apply(hier.chains[, grep(mu\\[, colnames(hier.chains))], 2, mean) ns - aggregate(therms$numstate, list(therms$stateabb), length) plot(mu.bar, mu.bar2, cex=sqrt(ns[,2])/3, xlab = FE mu[j], ylab = Hierarchical mu[j]) abline(a=0, b=1) ### ### code chunk number 7: dotchart ### fe.mu - FE.chains[,grep(mu\\[, colnames(FE.chains))] fe.ci - t(apply(fe.mu, 2, quantile, c(.5,.025,.975))) rownames(fe.ci) - unstate fe.ci - fe.ci[order(fe.ci[,1]), ] dotchart(fe.ci[order(fe.ci[,1]),1], lcolor=white, pch=16, xlim=range(c(fe.ci))) segments(fe.ci[,2], 1:34, fe.ci[,3], 1:34) mu.ci - quantile(exchange.chains[,1], c(.5,.025,.975)) polygon(x=mu.ci[c(2,3,3,2)], y = c(-1,-1,36,36), col=rgb(128,128,128,100, maxColorValue=255), border=NA) abline(v=mu.ci[1], lty=2, lwd=2) axis(4, at=1:34, labels=ns[match(rownames(fe.ci), ns[,1]),2], cex.axis=.75, las=2) ### ### code chunk number 8: femeans ### library(sm) sm.density(mu.bar, model=normal) [[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] problem with plots with short example.
To be clear everything runs with no error message... the only hint of a problem is at the end of the code: the plot will not fill out/ it is empty. if anyone has any idea why something like this might happen, i would greatly appreciate it... so i can handle it quickly. thanks in advance. On Mar 28, 2013, at 7:55 PM, Nicole Ford wrote: i am having problem running my own data. yesterday it was working just fine. today it is not. this is the code i was using as an example to follow. this code ALSO worked just fine yesterday, and is no longer working at all. i suspect it is a problem with either my computer or the software, at this point. if THIS won't even run something is wrong. i can assure you this isn't HW i know dave, but i am no longer at UW-M and i have never learned HLMs and i am learning this on my own for my own research. his code is here, along with data. it is short, quick, etc. http://www.quantoid.net/936/Lecture7.R ### R code from vignette source 'Lecture7.Rnw' ### ### code chunk number 1: opts ### options(useFancyQuotes=F) ### ### code chunk number 2: data1 ### library(foreign) therms - na.omit(read.dta(http://quantoid.net/936/2008_difftherm.dta;)) unstate - unique(therms[,1]) therms$numstate - match(therms$state, unstate) library(runjags) dat - dump.format(list( N = nrow(therms), J=length(unstate), y = therms$difftherm, numstate = therms$numstate )) ### ### code chunk number 3: exchange ### exchange.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu, tau) } mu ~ dnorm(0,.001) tau ~ dgamma(.1,.1) } exchange.out - run.jags(exchange.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 4: exchange ### FE.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(0,.001) tau[j] ~ dgamma(.1,.1) } } FE.out - run.jags(FE.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 5: exchange ### hier.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(theta,nu) tau[j] ~ dgamma(a,b) } theta ~ dnorm(0,.01) nu ~ dgamma(.1,.1) a ~ dunif(0,1000) b ~ dunif(0,1000) } hier.out - run.jags(hier.mod, data=dat, burnin=1, sample=10, thin=10, monitor=c(mu, tau, theta, nu, a, b), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 6: sums ### hier.chains - combine.mcmc(hier.out$mcmc) FE.chains - combine.mcmc(FE.out$mcmc) exchange.chains - combine.mcmc(exchange.out$mcmc) mu.bar - apply(FE.chains[, grep(mu\\[, colnames(FE.chains))], 2, mean) mu.bar2 - apply(hier.chains[, grep(mu\\[, colnames(hier.chains))], 2, mean) ns - aggregate(therms$numstate, list(therms$stateabb), length) plot(mu.bar, mu.bar2, cex=sqrt(ns[,2])/3, xlab = FE mu[j], ylab = Hierarchical mu[j]) abline(a=0, b=1) ### ### code chunk number 7: dotchart ### fe.mu - FE.chains[,grep(mu\\[, colnames(FE.chains))] fe.ci - t(apply(fe.mu, 2, quantile, c(.5,.025,.975))) rownames(fe.ci) - unstate fe.ci - fe.ci[order(fe.ci[,1]), ] dotchart(fe.ci[order(fe.ci[,1]),1], lcolor=white, pch=16, xlim=range(c(fe.ci))) segments(fe.ci[,2], 1:34, fe.ci[,3], 1:34) mu.ci - quantile(exchange.chains[,1], c(.5,.025,.975)) polygon(x=mu.ci[c(2,3,3,2)], y = c(-1,-1,36,36), col=rgb(128,128,128,100, maxColorValue=255), border=NA) abline(v=mu.ci[1], lty=2, lwd=2) axis(4, at=1:34, labels=ns[match(rownames(fe.ci), ns[,1]),2], cex.axis=.75, las=2) ### ### code chunk number 8: femeans ### library(sm) sm.density(mu.bar, model=normal) [[alternative HTML version
Re: [R] problem with plots with short example.
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Nicole Ford Sent: Thursday, March 28, 2013 4:55 PM To: r-help help Subject: [R] problem with plots with short example. i am having problem running my own data. yesterday it was working just fine. today it is not. this is the code i was using as an example to follow. this code ALSO worked just fine yesterday, and is no longer working at all. i suspect it is a problem with either my computer or the software, at this point. if THIS won't even run something is wrong. i can assure you this isn't HW i know dave, but i am no longer at UW-M and i have never learned HLMs and i am learning this on my own for my own research. his code is here, along with data. it is short, quick, etc. http://www.quantoid.net/936/Lecture7.R ### R code from vignette source 'Lecture7.Rnw' ### ### code chunk number 1: opts ### options(useFancyQuotes=F) ### ### code chunk number 2: data1 ### library(foreign) therms - na.omit(read.dta(http://quantoid.net/936/2008_difftherm.dta;)) unstate - unique(therms[,1]) therms$numstate - match(therms$state, unstate) library(runjags) dat - dump.format(list( N = nrow(therms), J=length(unstate), y = therms$difftherm, numstate = therms$numstate )) ### ### code chunk number 3: exchange ### exchange.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu, tau) } mu ~ dnorm(0,.001) tau ~ dgamma(.1,.1) } exchange.out - run.jags(exchange.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 4: exchange ### FE.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(0,.001) tau[j] ~ dgamma(.1,.1) } } FE.out - run.jags(FE.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 5: exchange ### hier.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(theta,nu) tau[j] ~ dgamma(a,b) } theta ~ dnorm(0,.01) nu ~ dgamma(.1,.1) a ~ dunif(0,1000) b ~ dunif(0,1000) } hier.out - run.jags(hier.mod, data=dat, burnin=1, sample=10, thin=10, monitor=c(mu, tau, theta, nu, a, b), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 6: sums ### hier.chains - combine.mcmc(hier.out$mcmc) FE.chains - combine.mcmc(FE.out$mcmc) exchange.chains - combine.mcmc(exchange.out$mcmc) mu.bar - apply(FE.chains[, grep(mu\\[, colnames(FE.chains))], 2, mean) mu.bar2 - apply(hier.chains[, grep(mu\\[, colnames(hier.chains))], 2, mean) ns - aggregate(therms$numstate, list(therms$stateabb), length) plot(mu.bar, mu.bar2, cex=sqrt(ns[,2])/3, xlab = FE mu[j], ylab = Hierarchical mu[j]) abline(a=0, b=1) ### ### code chunk number 7: dotchart ### fe.mu - FE.chains[,grep(mu\\[, colnames(FE.chains))] fe.ci - t(apply(fe.mu, 2, quantile, c(.5,.025,.975))) rownames(fe.ci) - unstate fe.ci - fe.ci[order(fe.ci[,1]), ] dotchart(fe.ci[order(fe.ci[,1]),1], lcolor=white, pch=16, xlim=range(c(fe.ci))) segments(fe.ci[,2], 1:34, fe.ci[,3], 1:34) mu.ci - quantile(exchange.chains[,1], c(.5,.025,.975)) polygon(x=mu.ci[c(2,3,3,2)], y = c(-1,-1,36,36), col=rgb(128,128,128,100, maxColorValue=255), border=NA) abline(v=mu.ci[1], lty=2, lwd=2) axis(4, at=1:34, labels=ns[match(rownames(fe.ci), ns[,1]),2], cex.axis=.75, las=2) ### ### code chunk number 8: femeans ### library(sm) sm.density(mu.bar, model=normal) Nicole, I am not going to be much help, other than to say I just downloaded and Installed the latest versions of JAGS for Windows, and the rjags and sm packages.
Re: [R] problem with plots with short example.
thank you, dan. any information, no matter how small, is helpful. i deleted R this moring and reinstalled it. outside of that i am not sure what else to delete/ reinstall. You mention you reinstalled JAGS- i will give that a try, as well. thanks! On Mar 28, 2013, at 8:52 PM, Nordlund, Dan (DSHS/RDA) wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Nicole Ford Sent: Thursday, March 28, 2013 4:55 PM To: r-help help Subject: [R] problem with plots with short example. i am having problem running my own data. yesterday it was working just fine. today it is not. this is the code i was using as an example to follow. this code ALSO worked just fine yesterday, and is no longer working at all. i suspect it is a problem with either my computer or the software, at this point. if THIS won't even run something is wrong. i can assure you this isn't HW i know dave, but i am no longer at UW-M and i have never learned HLMs and i am learning this on my own for my own research. his code is here, along with data. it is short, quick, etc. http://www.quantoid.net/936/Lecture7.R ### R code from vignette source 'Lecture7.Rnw' ### ### code chunk number 1: opts ### options(useFancyQuotes=F) ### ### code chunk number 2: data1 ### library(foreign) therms - na.omit(read.dta(http://quantoid.net/936/2008_difftherm.dta;)) unstate - unique(therms[,1]) therms$numstate - match(therms$state, unstate) library(runjags) dat - dump.format(list( N = nrow(therms), J=length(unstate), y = therms$difftherm, numstate = therms$numstate )) ### ### code chunk number 3: exchange ### exchange.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu, tau) } mu ~ dnorm(0,.001) tau ~ dgamma(.1,.1) } exchange.out - run.jags(exchange.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 4: exchange ### FE.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(0,.001) tau[j] ~ dgamma(.1,.1) } } FE.out - run.jags(FE.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 5: exchange ### hier.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(theta,nu) tau[j] ~ dgamma(a,b) } theta ~ dnorm(0,.01) nu ~ dgamma(.1,.1) a ~ dunif(0,1000) b ~ dunif(0,1000) } hier.out - run.jags(hier.mod, data=dat, burnin=1, sample=10, thin=10, monitor=c(mu, tau, theta, nu, a, b), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 6: sums ### hier.chains - combine.mcmc(hier.out$mcmc) FE.chains - combine.mcmc(FE.out$mcmc) exchange.chains - combine.mcmc(exchange.out$mcmc) mu.bar - apply(FE.chains[, grep(mu\\[, colnames(FE.chains))], 2, mean) mu.bar2 - apply(hier.chains[, grep(mu\\[, colnames(hier.chains))], 2, mean) ns - aggregate(therms$numstate, list(therms$stateabb), length) plot(mu.bar, mu.bar2, cex=sqrt(ns[,2])/3, xlab = FE mu[j], ylab = Hierarchical mu[j]) abline(a=0, b=1) ### ### code chunk number 7: dotchart ### fe.mu - FE.chains[,grep(mu\\[, colnames(FE.chains))] fe.ci - t(apply(fe.mu, 2, quantile, c(.5,.025,.975))) rownames(fe.ci) - unstate fe.ci - fe.ci[order(fe.ci[,1]), ] dotchart(fe.ci[order(fe.ci[,1]),1], lcolor=white, pch=16, xlim=range(c(fe.ci))) segments(fe.ci[,2], 1:34, fe.ci[,3], 1:34) mu.ci - quantile(exchange.chains[,1], c(.5,.025,.975)) polygon(x=mu.ci[c(2,3,3,2)], y = c(-1,-1,36,36), col=rgb(128,128,128,100, maxColorValue=255), border=NA) abline(v=mu.ci[1], lty=2, lwd=2) axis(4, at=1:34, labels=ns[match(rownames(fe.ci), ns[,1]),2], cex.axis=.75, las=2) ### ### code chunk number 8: femeans
Re: [R] Help partimat()
On Mar 28, 2013, at 1:45 PM, Antelmo Aguilar wrote: Hello Everyone, I was wondering if anyone knows a solution to a problem I am experiencing. I have an R script that creates multiple graphs of the data in several data file using the partimat() function that is located in the klaR library. I would like to get this graphs into a single image similar to the way one can use the par() function and then the plot() function to put multiple plots side by side. The problem is that the par() function does not work with partimat() so I was wondering if there is an equivalent way of achieving the same result when using partimat(). I have searched for several hours already and I have not been able to find a solution. I would greatly appreciate any help. Attached is the script as well as the end result I would like to get after running the script. What happens is that inside the partimat.default function this line appears: opar - par(mfrow = c(nvar, nvar), mar = mar, oma = rep(3, 4), xpd = NA) So the graphics setup is being driven by the structure of the data that is being given (which you have not described.) -- 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] problem with plots with short example.
Hi Nicole I just upgraded to 2.15.3 today I was just having similar problems with run.jags and it stopping dead in its tracks with an error message pointing to somewhere else See ?run.jags and the second paragraph of it. I then got it to run using a run.jags script using Rterm and saved the model. By accident I copied and pasted a script to R with run.jags in it and it now runs. see also ?test.jags Do not know what will happen after a reboot. HTH Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 10:24 29/03/2013, you wrote: To be clear everything runs with no error message... the only hint of a problem is at the end of the code: the plot will not fill out/ it is empty. if anyone has any idea why something like this might happen, i would greatly appreciate it... so i can handle it quickly. thanks in advance. On Mar 28, 2013, at 7:55 PM, Nicole Ford wrote: i am having problem running my own data. yesterday it was working just fine. today it is not. this is the code i was using as an example to follow. this code ALSO worked just fine yesterday, and is no longer working at all. i suspect it is a problem with either my computer or the software, at this point. if THIS won't even run something is wrong. i can assure you this isn't HW i know dave, but i am no longer at UW-M and i have never learned HLMs and i am learning this on my own for my own research. his code is here, along with data. it is short, quick, etc. http://www.quantoid.net/936/Lecture7.R ### R code from vignette source 'Lecture7.Rnw' ### ### code chunk number 1: opts ### options(useFancyQuotes=F) ### ### code chunk number 2: data1 ### library(foreign) therms - na.omit(read.dta(http://quantoid.net/936/2008_difftherm.dta;)) unstate - unique(therms[,1]) therms$numstate - match(therms$state, unstate) library(runjags) dat - dump.format(list( N = nrow(therms), J=length(unstate), y = therms$difftherm, numstate = therms$numstate )) ### ### code chunk number 3: exchange ### exchange.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu, tau) } mu ~ dnorm(0,.001) tau ~ dgamma(.1,.1) } exchange.out - run.jags(exchange.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 4: exchange ### FE.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(0,.001) tau[j] ~ dgamma(.1,.1) } } FE.out - run.jags(FE.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 5: exchange ### hier.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(theta,nu) tau[j] ~ dgamma(a,b) } theta ~ dnorm(0,.01) nu ~ dgamma(.1,.1) a ~ dunif(0,1000) b ~ dunif(0,1000) } hier.out - run.jags(hier.mod, data=dat, burnin=1, sample=10, thin=10, monitor=c(mu, tau, theta, nu, a, b), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 6: sums ### hier.chains - combine.mcmc(hier.out$mcmc) FE.chains - combine.mcmc(FE.out$mcmc) exchange.chains - combine.mcmc(exchange.out$mcmc) mu.bar - apply(FE.chains[, grep(mu\\[, colnames(FE.chains))], 2, mean) mu.bar2 - apply(hier.chains[, grep(mu\\[, colnames(hier.chains))], 2, mean) ns - aggregate(therms$numstate, list(therms$stateabb), length) plot(mu.bar, mu.bar2, cex=sqrt(ns[,2])/3, xlab = FE mu[j], ylab = Hierarchical mu[j]) abline(a=0, b=1) ### ### code chunk number 7: dotchart ### fe.mu - FE.chains[,grep(mu\\[, colnames(FE.chains))] fe.ci - t(apply(fe.mu, 2, quantile, c(.5,.025,.975))) rownames(fe.ci) - unstate fe.ci - fe.ci[order(fe.ci[,1]), ] dotchart(fe.ci[order(fe.ci[,1]),1], lcolor=white, pch=16, xlim=range(c(fe.ci)))
Re: [R] problem with plots with short example.
I was up till 4 am with this sucker trying to figure it out- I thought i lost my mind/ screwed it up somehow. I guess it's nice to know it really wasn't me. Though, I AM sad R is messing up- first time in over 3 years, so I guess it isn't so bad. But timing couldn't have been worse, as I have a conference coming up. Thanks very much, Duncan! I am going to give that a whirl tomorrow! On Mar 28, 2013, at 10:37 PM, Duncan Mackay wrote: Hi Nicole I just upgraded to 2.15.3 today I was just having similar problems with run.jags and it stopping dead in its tracks with an error message pointing to somewhere else See ?run.jags and the second paragraph of it. I then got it to run using a run.jags script using Rterm and saved the model. By accident I copied and pasted a script to R with run.jags in it and it now runs. see also ?test.jags Do not know what will happen after a reboot. HTH Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 10:24 29/03/2013, you wrote: To be clear everything runs with no error message... the only hint of a problem is at the end of the code: the plot will not fill out/ it is empty. if anyone has any idea why something like this might happen, i would greatly appreciate it... so i can handle it quickly. thanks in advance. On Mar 28, 2013, at 7:55 PM, Nicole Ford wrote: i am having problem running my own data. yesterday it was working just fine. today it is not. this is the code i was using as an example to follow. this code ALSO worked just fine yesterday, and is no longer working at all. i suspect it is a problem with either my computer or the software, at this point. if THIS won't even run something is wrong. i can assure you this isn't HW i know dave, but i am no longer at UW-M and i have never learned HLMs and i am learning this on my own for my own research. his code is here, along with data. it is short, quick, etc. http://www.quantoid.net/936/Lecture7.R ### R code from vignette source 'Lecture7.Rnw' ### ### code chunk number 1: opts ### options(useFancyQuotes=F) ### ### code chunk number 2: data1 ### library(foreign) therms - na.omit(read.dta(http://quantoid.net/936/2008_difftherm.dta;)) unstate - unique(therms[,1]) therms$numstate - match(therms$state, unstate) library(runjags) dat - dump.format(list( N = nrow(therms), J=length(unstate), y = therms$difftherm, numstate = therms$numstate )) ### ### code chunk number 3: exchange ### exchange.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu, tau) } mu ~ dnorm(0,.001) tau ~ dgamma(.1,.1) } exchange.out - run.jags(exchange.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 4: exchange ### FE.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(0,.001) tau[j] ~ dgamma(.1,.1) } } FE.out - run.jags(FE.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 5: exchange ### hier.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu[numstate[i]], tau[numstate[i]]) } for(j in 1:J){ mu[j] ~ dnorm(theta,nu) tau[j] ~ dgamma(a,b) } theta ~ dnorm(0,.01) nu ~ dgamma(.1,.1) a ~ dunif(0,1000) b ~ dunif(0,1000) } hier.out - run.jags(hier.mod, data=dat, burnin=1, sample=10, thin=10, monitor=c(mu, tau, theta, nu, a, b), monitor.deviance=T, monitor.pd=T, silent.jags=T) ### ### code chunk number 6: sums ### hier.chains - combine.mcmc(hier.out$mcmc) FE.chains - combine.mcmc(FE.out$mcmc) exchange.chains - combine.mcmc(exchange.out$mcmc) mu.bar - apply(FE.chains[, grep(mu\\[, colnames(FE.chains))], 2, mean) mu.bar2 - apply(hier.chains[, grep(mu\\[, colnames(hier.chains))], 2, mean) ns
Re: [R] problem with plots with short example.
LOL dennis, thanks for the laugh at the end. I'm a PhD student... I had never used it before until this last semester when i started taking Bayes at my new university (transfer because of husband's job =\). My old dept offered bayes, but not the new one, so i am taking it in the psychology dept the application (lots of binary outcomes and t-test focused) isn't terribly useful for my own discipline (poli sci, where ALL i do is LM and logistic and now HLM!) but it -at least- has exposed me to how to use bayes, JAGS, etc. so it isn't completely foreign to me. I am on a mac and, for whatever reason (until the latest update), I was NEVER able to run any code on it. it was always always locking up on me everyone else in the class was using it (we use the Kruschke book and he has code, etc and recommnds it) so I was determinded to get it to work always ended in HOURS and HOURS of frustration and me just saying *screw it* and going to R and completing the task in 30 minutes. =b but like i said, since they have updated it (was in Jan of Feb?), i haven't had any issues but, MAN was that a frustrating 5/6 months. it really put a sour taste in my mouth. but, i will say- thank god for R-studio right now. lol totally saved my sanity. but i am determined to fix R... On Mar 28, 2013, at 10:45 PM, Dennis Murphy wrote: Hi Nicole: On Thu, Mar 28, 2013 at 7:25 PM, Nicole Ford nicole.f...@me.com wrote: thank you, dennis, but that's ok! i ran it all successfully yesterday, as well as my own any ideas why it would blow up like this and not plot? Sorry, no. Given the tenor of some of your posts today, I wondered if your computer had contracted a virus. Progressively weird behavior is often a sign, as is a noticeable slowdown in performance. what's interesting is: was able to run my own research just fine (JUST NOW finished) in R-studio (YUK), so something is definitely corrupt in the R environment. I wish I could figure it out! i HATE using R-studio. =\ I have certain issues with it, but I like RStudio for documentation writing and I'm about to start package development using RStudio projects in conjunction with Git. If you use script files instead of typing at the command line or copy/pasting from a text editor, it's easy to bounce back and forth between the two; the only thing I miss is the 'Run selection' feature in R GUI script shells running under Windows. If you're an R package developer, it's definitely the way to go, especially if you're using Git and devtools. Why do you hate RStudio so much? (I'm envisioning a Sanka commercial with Robert Young from the 70s where the commercial opens with the line: Hey, why so tense? :) [I can guess why, but I'll leave it at that.] To quote the great psychologist Cesar Millan, stay calm and assertive :) Dennis On Mar 28, 2013, at 10:13 PM, Dennis Murphy wrote: Hi Nicole: I, too, ran the script file without error, but a set of warnings. Here's the output from the R console: source(Lecture7.R.txt) Loading required package: coda Loading required package: lattice Loading required package: parallel Calling the simulation... (this may take some time) Simulation complete. Reading coda files... Coda files loaded successfully Abstracting pD ... 5 valid values Calculating the Gelman-Rubin statistic for 3 variables The Gelman-Rubin statistic is below 1.05 for all parameters Finished running the simulation Calling the simulation... (this may take some time) Simulation complete. Reading coda files... Coda files loaded successfully Abstracting pD ... 5 valid values Calculating the Gelman-Rubin statistic for 69 variables The Gelman-Rubin statistic is below 1.05 for all parameters Finished running the simulation Calling the simulation... (this may take some time) Simulation complete. Reading coda files... Coda files loaded successfully Abstracting pD ... 10 valid values Calculating the Gelman-Rubin statistic for 73 variables The Gelman-Rubin statistic is below 1.05 for all parameters Finished running the simulation Package `sm', version 2.2-4.1 Copyright (C) 1997, 2000, 2005, 2007, 2008, A.W.Bowman A.Azzalini Type help(sm) for summary information Loading required package: Matrix Attaching package: 'lme4' The following object(s) are masked from 'package:coda': HPDinterval The following object(s) are masked from 'package:stats': AIC, BIC Calling the simulation... (this may take some time) Simulation complete. Reading coda files... Coda files loaded successfully Calculating the Gelman-Rubin statistic for 9 variables The Gelman-Rubin statistic is below 1.05 for all parameters Finished running the simulation Calling the simulation... (this may take some time) Simulation complete. Reading coda files... Coda files loaded successfully Calculating the Gelman-Rubin statistic for 10 variables The
Re: [R] problem with plots with short example.
Hi Nicole My code works using source file if I put library(runjags) x = testjags(findjags(windows,look_in = c:/Program Files/JAGS)) source(G:/Sweave/Bayes.R) works ok Further developments with Sweave. Putting this in the Sweave file library(runjags) x = testjags(findjags(windows,look_in = c:/Program Files/JAGS)) x ... $JAGS.available [1] TRUE $JAGS.path [1] \c:/Program Files/JAGS/JAGS-3.3.0/i386/bin/jags-terminal.exe\ ... If I do not setwd() everything works fine for runjags but have not tried to plot any plots as pdf Unfortunately it comes up in my default c:\Users\d mackay\Documents\ Using setwd() before Sweave(G:/Sweave/Bayes.Rnw) and in the Sweave file # \Sweave file before run.jags call x = testjags(findjags(windows,look_in = c:/Program Files/JAGS)) It returns this error in the R command window Error: chunk 7 (label = JAGS2) Error in run.jags(model = mod, monitor = p, init = list(init1, init2), : Unable to call JAGS However x shows that it is finding JAGS x ... $JAGS.available [1] TRUE $JAGS.path [1] \c:/Program Files/JAGS/JAGS-3.3.0/i386/bin/jags-terminal.exe\ ... Latex tex file You are currently logged on as d mackay, on a windows machine You are using R version 2.15.3 (2013-03-01), with the Rgui GUI JAGS version 3.3.0 found successfully using the command c:/Program Files/JAGS/JAGS-3.3.0/i386/bin/jags-terminal.exe So do not use setwd or change directory from the gui menu and it works but things end up where your default directory is I am not sure what is going on but any assistance to fix it would be appreciated. Regards Duncan At 12:45 29/03/2013, you wrote: I was up till 4 am with this sucker trying to figure it out- I thought i lost my mind/ screwed it up somehow. I guess it's nice to know it really wasn't me. Though, I AM sad R is messing up- first time in over 3 years, so I guess it isn't so bad. But timing couldn't have been worse, as I have a conference coming up. Thanks very much, Duncan! I am going to give that a whirl tomorrow! On Mar 28, 2013, at 10:37 PM, Duncan Mackay wrote: Hi Nicole I just upgraded to 2.15.3 today I was just having similar problems with run.jags and it stopping dead in its tracks with an error message pointing to somewhere else See ?run.jags and the second paragraph of it. I then got it to run using a run.jags script using Rterm and saved the model. By accident I copied and pasted a script to R with run.jags in it and it now runs. see also ?test.jags Do not know what will happen after a reboot. HTH Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 10:24 29/03/2013, you wrote: To be clear everything runs with no error message... the only hint of a problem is at the end of the code: the plot will not fill out/ it is empty. if anyone has any idea why something like this might happen, i would greatly appreciate it... so i can handle it quickly. thanks in advance. On Mar 28, 2013, at 7:55 PM, Nicole Ford wrote: i am having problem running my own data. yesterday it was working just fine. today it is not. this is the code i was using as an example to follow. this code ALSO worked just fine yesterday, and is no longer working at all. i suspect it is a problem with either my computer or the software, at this point. if THIS won't even run something is wrong. i can assure you this isn't HW i know dave, but i am no longer at UW-M and i have never learned HLMs and i am learning this on my own for my own research. his code is here, along with data. it is short, quick, etc. http://www.quantoid.net/936/Lecture7.R ### R code from vignette source 'Lecture7.Rnw' ### ### code chunk number 1: opts ### options(useFancyQuotes=F) ### ### code chunk number 2: data1 ### library(foreign) therms - na.omit(read.dta(http://quantoid.net/936/2008_difftherm.dta;)) unstate - unique(therms[,1]) therms$numstate - match(therms$state, unstate) library(runjags) dat - dump.format(list( N = nrow(therms), J=length(unstate), y = therms$difftherm, numstate = therms$numstate )) ### ### code chunk number 3: exchange ### exchange.mod - model{ for(i in 1:N){ y[i] ~ dnorm(mu, tau) } mu ~ dnorm(0,.001) tau ~ dgamma(.1,.1) } exchange.out - run.jags(exchange.mod, data=dat, burnin=1, sample=5, thin=5, monitor=c(mu, tau), monitor.deviance=T, monitor.pd=T, silent.jags=T)
Re: [R] how to search a list that contains multiple dissimilarvectors?
Gerrit, Eik -- Thanks very much for your replies! This answers my primary question -- was I missing some simple command that did not resort to function() in some manner. Both are much more streamlined than my 7 line laughable beast of solution. Best, Eric On Mar 28, 2013, at 2:29 AM, Gerrit Eichner wrote: Hi, Eric, as a quick hack, does spots - sapply( alist, function( listcomp) which( listcomp == value.to.look.for) ) spots[ sapply( spots, length) == 0] - NULL do what you want? Regards -- Gerrit On Mar 28, 2013, at 2:21 AM, Eik Vettorazzi wrote: Hi Eric, something like the following might me a starter (index-lapply(alist,function(x)which(x==x.search))) cheers. Am 28.03.2013 08:40, schrieb Eric Rupley: Dear All, This is a simple question, but I'm stumped about the simplest way to search a list object such as the following: This randomish snippet: n - c(round(runif(round(runif(1,1,10),0),1,10),0)) alist - new(list) for (i in seq_along(n)) { alist[[i]] - c(round(runif(round(runif(1,1,10),0),1,10),0)) } names(alist) - sample(letters[1:length(n)]) rm(n);c(alist) ...produces something like this: $d [1] 4 $b [1] 3 5 3 $a [1] 2 5 7 3 10 3 4 9 9 $c [1] 6 3 7 4 5 10 8 10 3 My question is how does one search the list for a given value, in a most compressed set of commands, in order two return two separate indices: a) the index of the list element(s) containing the value, and b) the index of the matching value(s) within the vector. Right now, I'm writing cumbersome loops to iterate though the elements, but there must be a simple, effective method to which I have not found a reference. Many thanks in advance, and apologies if I have overlooked a reference passage. Best, Eric -- Eric Rupley University of Michigan, Museum of Anthropology 1109 Geddes Ave, Rm. 4013 Ann Arbor, MI 48109-1079 __ 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.