Re: [R] Removing NAs from dataframe (for use in Vioplot)

2016-04-30 Thread Jeff Newmiller
But require() should not be used interchangeably with library()... the return 
value from require() should always be tested. 
-- 
Sent from my phone. Please excuse my brevity.

On May 1, 2016 3:03:59 AM GMT+01:00, Tom Wright  wrote:
>Never let it be said there's only one way to do a thing:
>
>require(ggplot2)
>require(dplyr)
>
>#create a sample dataset
>dat <- data.frame(y1=sample(c(1:10,NA),20,replace=TRUE),
>  y2=sample(c(1:10,NA),20,replace=TRUE),
>  y3=sample(c(1:10,NA),20,replace=TRUE))
>
># convert from wide to long
>dat <- melt(dat)
>
># add the counts as a label
>dat <- merge(dat,
>  group_by(dat,variable) %>%
>   summarise(lab=paste0('n=',length(na.omit(value)
>
># do the plot
>ggplot(dat,aes(x=variable,y=value)) +
>geom_violin() +
>geom_text(aes(y=max(value,na.rm=TRUE)/2,label=lab))
>
>
># apologies to David Winsemius for directing this answer to him, I'll
>work
>out how to use email one day.
>
>On Sat, Apr 30, 2016 at 12:58 PM, Mike Smith  wrote:
>
>> Hi
>>
>> First post and a relative R newbie
>>
>> I am using the vioplot library to produce some violin plots. I have
>an
>> input CSV with columns off irregular length that contain NAs. I want
>to
>> strip the NAs out and produce a multiple violin plot automatically
>labelled
>> using the headers. At the moment I do this
>>
>> Code:
>> ds1 = read.csv("http://www.lecturematerials.co.uk/data/spelling.csv;)
>> library(vioplot)
>> y6<-na.omit(ds1$y6)
>> y5<-na.omit(ds1$y5)
>> y4<-na.omit(ds1$y4)
>> y3<-na.omit(ds1$y3)
>> y2<-na.omit(ds1$y2)
>> y1<-na.omit(ds1$y1)
>> vioplot(y6, y5, y4,y3,y2,y1,horizontal=TRUE, names=c("Y6",
>> "Y5","Y4","Y3","Y2","Y1"), col = "lightblue")
>>
>>
>> Two queries:
>>
>> 1. Is there a more elegant way of automatically stripping the NAs,
>passing
>> the columns to the function along with the header names??
>>
>> 2. Can I easily add the sample size to each violin plotted??
>>
>> thanks
>>
>> mike
>>
>>
>>
>> ---
>> Mike Smith
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 -- To UNSUBSCRIBE and more, see
>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 -- To UNSUBSCRIBE and more, see
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 use AND in grepl

2016-04-30 Thread Tom Wright
Actually not sure my previous answer does what you wanted. Using your
approach:

 t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))

Should work.

I think the regex pattern you are looking for is:

 Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)

On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:

> subset(df,grepl("t2|pd",x$Command))
>
>
> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  > wrote:
>
>> Hi all,
>>
>> I have one factor variable in my df and I want to extract the names from
>> it which contain both "t2" and "pd":
>>
>>   'data.frame': 36919 obs. of 162 variables
>>$TE:int 38,41,11,52,48,75,.
>>$TR:int 100,210,548,546,.
>>$Command  :factor W/2229 levels
>> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>>
>> I have tried this but I did not get result:
>>
>>   t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>>
>>
>> does anyone know how to apply AND in grepl?
>>
>> Thanks
>> Elahe
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 -- To UNSUBSCRIBE and more, see
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 use AND in grepl

2016-04-30 Thread Tom Wright
subset(df,grepl("t2|pd",x$Command))


On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help 
wrote:

> Hi all,
>
> I have one factor variable in my df and I want to extract the names from
> it which contain both "t2" and "pd":
>
>   'data.frame': 36919 obs. of 162 variables
>$TE:int 38,41,11,52,48,75,.
>$TR:int 100,210,548,546,.
>$Command  :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>
> I have tried this but I did not get result:
>
>   t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>
>
> does anyone know how to apply AND in grepl?
>
> Thanks
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] Removing NAs from dataframe (for use in Vioplot)

2016-04-30 Thread Tom Wright
Never let it be said there's only one way to do a thing:

require(ggplot2)
require(dplyr)

#create a sample dataset
dat <- data.frame(y1=sample(c(1:10,NA),20,replace=TRUE),
  y2=sample(c(1:10,NA),20,replace=TRUE),
  y3=sample(c(1:10,NA),20,replace=TRUE))

# convert from wide to long
dat <- melt(dat)

# add the counts as a label
dat <- merge(dat,
  group_by(dat,variable) %>%
   summarise(lab=paste0('n=',length(na.omit(value)

# do the plot
ggplot(dat,aes(x=variable,y=value)) +
geom_violin() +
geom_text(aes(y=max(value,na.rm=TRUE)/2,label=lab))


# apologies to David Winsemius for directing this answer to him, I'll work
out how to use email one day.

On Sat, Apr 30, 2016 at 12:58 PM, Mike Smith  wrote:

> Hi
>
> First post and a relative R newbie
>
> I am using the vioplot library to produce some violin plots. I have an
> input CSV with columns off irregular length that contain NAs. I want to
> strip the NAs out and produce a multiple violin plot automatically labelled
> using the headers. At the moment I do this
>
> Code:
> ds1 = read.csv("http://www.lecturematerials.co.uk/data/spelling.csv;)
> library(vioplot)
> y6<-na.omit(ds1$y6)
> y5<-na.omit(ds1$y5)
> y4<-na.omit(ds1$y4)
> y3<-na.omit(ds1$y3)
> y2<-na.omit(ds1$y2)
> y1<-na.omit(ds1$y1)
> vioplot(y6, y5, y4,y3,y2,y1,horizontal=TRUE, names=c("Y6",
> "Y5","Y4","Y3","Y2","Y1"), col = "lightblue")
>
>
> Two queries:
>
> 1. Is there a more elegant way of automatically stripping the NAs, passing
> the columns to the function along with the header names??
>
> 2. Can I easily add the sample size to each violin plotted??
>
> thanks
>
> mike
>
>
>
> ---
> Mike Smith
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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 print the frequency table (produced by the command "table" to Excel

2016-04-30 Thread jpm miao
Thanks.
Could we print the row/column names, "alpha1" and "alpha2" to the csv file?

2016-04-30 17:06 GMT-07:00 Jim Lemon :

> Hi jpm miao,
> I think you can get what you want like this:
>
> alpha1<-sample(LETTERS[1:3],50,TRUE)
> alpha2<-sample(LETTERS[1:2],50,TRUE)
> alphas<-data.frame(alpha1,alpha2)
> library(prettyR)
> alphatab<-xtab(alpha1~alpha2,alphas)
> sink("temp_table3.csv",append=TRUE)
> delim.xtab(alphatab,pct=NA,delim=",")
> sink()
>
> Jim
>
> On Sun, May 1, 2016 at 4:47 AM, jpm miao  wrote:
> > Jim,
> >
> >Thanks for creating such a fantastic package "prettyR".
> >I want to print the pretty frequency table (with row total and column
> > total) to an excel (or csv ) file. Is it possible?
> >>alphatab
> >
> > A B Total
> > A 8 10 18
> > B 7 5 12
> > C 9 11 20
> > Total 24 26 50
> >
> >Two issues I encountered (See the attached csv file).
> > 1. When I tried to print the above table to csv file, all elements on the
> > same row are printed in one cell.
> > 2. If I write "delim.table(alpha tab)", the table is distorted (see
> > attached). Of course, I can adjust it manually but sometimes the number
> of
> > files is big.
> >
> > Thanks!
> >
> > Miao
> >
> >> alpha1<-sample(LETTERS[1:3],50,TRUE)
> >> alpha2<-sample(LETTERS[1:2],50,TRUE)
> >>
> >> alphas<-data.frame(alpha1,alpha2)
> >> alphatab<-xtab(alpha1~alpha2,alphas)
> > Crosstabulation of alpha1 by alpha2
> > alpha2
> > alpha1  A  B
> > A  8 10 18
> >44.44  55.56  -
> >33.33  38.46  36.00
> >
> > B  7  5 12
> >58.33  41.67  -
> >29.17  19.23  24.00
> >
> > C  9 11 20
> >   45 55  -
> >37.50  42.31  40.00
> >
> >   24 26 50
> >   48 52100
> >> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
> > alphatab
> >
> > A B Total
> > A 8 10 18
> > B 7 5 12
> > C 9 11 20
> > Total 24 26 50
> >
> >> sink("temp_table3.csv")
> >> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
> >> sink()
> >> sink("temp_table3.csv", append=TRUE)
> >> delim.table(alphatab)
> >> sink()
> >> sink("temp_table3.csv", append=TRUE)
> >> delim.table(alphatab)
> >> sink()
> >> ?delim.xtab
> >
> >
> > 2016-04-26 16:14 GMT-07:00 Jim Lemon :
> >>
> >> Hi jpm miao,
> >> You can get CSV files that can be imported into Excel like this:
> >>
> >> library(prettyR)
> >> sink("excel_table1.csv")
> >> delim.table(table(df[,c("y","z")]))
> >> sink()
> >> sink("excel_table2.csv")
> >> delim.table(as.data.frame(table(df[,c("y","z")])),label="")
> >> sink()
> >> sink("excel_table3.csv")
> >> delim.table(as.matrix(table(df[,c("y","z")])),label="")
> >> sink()
> >>
> >> Jim
> >>
> >> On Wed, Apr 27, 2016 at 8:35 AM, jpm miao  wrote:
> >> > Hi,
> >> >
> >> >How could we print the frequency table (produced by "table") to an
> >> > Excel
> >> > file?
> >> >Is there an easy way to do so? Thanks,
> >> >
> >> > Miao
> >> >
> >> >> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3])
> >> >
> >> >> table(df[,c("y","z")])
> >> >z
> >> > y   a b c
> >> >   1 0 0 1
> >> >   2 0 1 0
> >> >   3 1 0 0
> >> >> test<-table(df[,c("y","z")])
> >> >> as.data.frame(test)
> >> >   y z Freq
> >> > 1 1 a0
> >> > 2 2 a0
> >> > 3 3 a1
> >> > 4 1 b0
> >> > 5 2 b1
> >> > 6 3 b0
> >> > 7 1 c1
> >> > 8 2 c0
> >> > 9 3 c0
> >> >> as.matrix(test)
> >> >z
> >> > y   a b c
> >> >   1 0 0 1
> >> >   2 0 1 0
> >> >   3 1 0 0
> >> >> testm<-as.matrix(test)
> >> >> testm
> >> >z
> >> > y   a b c
> >> >   1 0 0 1
> >> >   2 0 1 0
> >> >   3 1 0 0
> >> >> typeof(testm)
> >> > [1] "integer"
> >> >
> >> > [[alternative HTML version deleted]]
> >> >
> >> > __
> >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> > 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 -- To UNSUBSCRIBE and more, see
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] Could not find function "pointsToRaster"

2016-04-30 Thread Ben Tupper
Hi,

I think you need to check the order of your arguments to rasterize().  See the 
documentation with ?rasterize and compare to what you did below.

Cheers,
Ben

 
> On Apr 30, 2016, at 9:55 AM, Ogbos Okike  wrote:
> 
> Dear All,
> Thanks for your inputs. I did replace pointsToRaster () with
> raster::rasterize(). Below is part of my script.
> 
> But I got another error:
> Error in (function (classes, fdef, mtable)  :
>  unable to find an inherited method for function ‘rasterize’ for
> signature ‘"RasterLayer", "matrix"’
> 
> Thank you for more inputs.
> Ogbos
> 
> k<-read.table("Lat05w3.txt")
> colnames(k)<-c("y","x")
> xy<-cbind(k$x,k$y)
> library(raster)
> r<-raster()
> #library(sp)
> pr<-raster::rasterize(r,xy)
> 
> #pr<-pointsToRaster(r,xy)
> 
> library(maps)
> w = map("world")
> wc = cbind(w$x, w$y)
> wc=wc[!is.na(wc[,1]),]
> write.table(wc, file = "my.fileb", sep=" ",row=FALSE,col=FALSE)
> my<-read.table("my.out",col.names=c("a","b"))
> rena = function(X,Z){
> Y=rep(NA,length(X))
> Y[!is.na(X)]=Z
> Y
> }
> 
> 
> 
> 
> On 4/30/16, Ben Tupper  wrote:
>> Hi,
>> 
>> A terrific resource for this type of issue (and pretty much anything related
>> to R) is http://rseek.org/  I'm sure I use it at least daily.  Check out
>> ...
>> 
>> http://rseek.org/?q=pointsToRaster
>> 
>> The first hit is about pointsToRaster() - it has been replaced by
>> raster::rasterize()
>> 
>> Cheers,
>> Ben
>> 
>>> On Apr 30, 2016, at 4:28 AM, Ogbos Okike 
>>> wrote:
>>> 
>>> Dear All,
>>> I have a script that draws longitude and latitude of lightning
>>> occurrence. This script was running fine before. But when I changed my
>>> system and do a fresh install on another laptop, this error persist.
>>> source("script")
>>> Error in eval(expr, envir, enclos) :
>>> could not find function "pointsToRaster"
>>> 
>>> I have tried to see if  there is any other package I need to install
>>> to take of the problem, I could not see. Already, when I installed
>>> raster, it installed its dependencies such as sp.
>>> Can any body please bail me out.
>>> 
>>> Thanks
>>> Ogbos
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>> 
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>> 
>> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Issue installing packages - Linux

2016-04-30 Thread Jim Lemon
Hi Lars,
A mystery, but for the bodgy characters in your error message. Perhaps
there is a problem with R trying to read a different character set
from that used in the package.

Jim

On Sat, Apr 30, 2016 at 8:22 PM, Lars Bishop  wrote:
> Hello,
>
> I can’t seem to be able to install packages on a redhat-linux-gnu. For
> instance, this is what happens when I try to install “bitops”. Any hint on
> what might be the issue would be much appreciated.
>
>> sessionInfo()
> R version 3.2.3 (2015-12-10)
> Platform: x86_64-redhat-linux-gnu (64-bit)
> Running under: Red Hat Enterprise Linux
>
>> Sys.setenv(https_proxy="https://labproxy.com:8080;)
>> install.packages("bitops", lib="mypath ")
>
> Here I choose: 22: (HTTP mirrors) and then a mirror 16:Canada(ON)
>
> * installing *source* package âbitopsâ ...
> ** package âbitopsâ successfully unpacked and MD5 sums checked
> Error in readRDS(pfile) : error reading from connection
> ERROR: lazy loading failed for package âbitopsâ
>
> I’ve also tried from the shell (after downloading the package source)
>
> $  R CMD INSTALL bitops_1.0-6.tar.gz
> ERROR: cannot extract package from bitops_1.0-6.tar.gz
>
> Thank you,
> Lars.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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 print the frequency table (produced by the command "table" to Excel

2016-04-30 Thread Jim Lemon
Hi jpm miao,
I think you can get what you want like this:

alpha1<-sample(LETTERS[1:3],50,TRUE)
alpha2<-sample(LETTERS[1:2],50,TRUE)
alphas<-data.frame(alpha1,alpha2)
library(prettyR)
alphatab<-xtab(alpha1~alpha2,alphas)
sink("temp_table3.csv",append=TRUE)
delim.xtab(alphatab,pct=NA,delim=",")
sink()

Jim

On Sun, May 1, 2016 at 4:47 AM, jpm miao  wrote:
> Jim,
>
>Thanks for creating such a fantastic package "prettyR".
>I want to print the pretty frequency table (with row total and column
> total) to an excel (or csv ) file. Is it possible?
>>alphatab
>
> A B Total
> A 8 10 18
> B 7 5 12
> C 9 11 20
> Total 24 26 50
>
>Two issues I encountered (See the attached csv file).
> 1. When I tried to print the above table to csv file, all elements on the
> same row are printed in one cell.
> 2. If I write "delim.table(alpha tab)", the table is distorted (see
> attached). Of course, I can adjust it manually but sometimes the number of
> files is big.
>
> Thanks!
>
> Miao
>
>> alpha1<-sample(LETTERS[1:3],50,TRUE)
>> alpha2<-sample(LETTERS[1:2],50,TRUE)
>>
>> alphas<-data.frame(alpha1,alpha2)
>> alphatab<-xtab(alpha1~alpha2,alphas)
> Crosstabulation of alpha1 by alpha2
> alpha2
> alpha1  A  B
> A  8 10 18
>44.44  55.56  -
>33.33  38.46  36.00
>
> B  7  5 12
>58.33  41.67  -
>29.17  19.23  24.00
>
> C  9 11 20
>   45 55  -
>37.50  42.31  40.00
>
>   24 26 50
>   48 52100
>> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
> alphatab
>
> A B Total
> A 8 10 18
> B 7 5 12
> C 9 11 20
> Total 24 26 50
>
>> sink("temp_table3.csv")
>> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
>> sink()
>> sink("temp_table3.csv", append=TRUE)
>> delim.table(alphatab)
>> sink()
>> sink("temp_table3.csv", append=TRUE)
>> delim.table(alphatab)
>> sink()
>> ?delim.xtab
>
>
> 2016-04-26 16:14 GMT-07:00 Jim Lemon :
>>
>> Hi jpm miao,
>> You can get CSV files that can be imported into Excel like this:
>>
>> library(prettyR)
>> sink("excel_table1.csv")
>> delim.table(table(df[,c("y","z")]))
>> sink()
>> sink("excel_table2.csv")
>> delim.table(as.data.frame(table(df[,c("y","z")])),label="")
>> sink()
>> sink("excel_table3.csv")
>> delim.table(as.matrix(table(df[,c("y","z")])),label="")
>> sink()
>>
>> Jim
>>
>> On Wed, Apr 27, 2016 at 8:35 AM, jpm miao  wrote:
>> > Hi,
>> >
>> >How could we print the frequency table (produced by "table") to an
>> > Excel
>> > file?
>> >Is there an easy way to do so? Thanks,
>> >
>> > Miao
>> >
>> >> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3])
>> >
>> >> table(df[,c("y","z")])
>> >z
>> > y   a b c
>> >   1 0 0 1
>> >   2 0 1 0
>> >   3 1 0 0
>> >> test<-table(df[,c("y","z")])
>> >> as.data.frame(test)
>> >   y z Freq
>> > 1 1 a0
>> > 2 2 a0
>> > 3 3 a1
>> > 4 1 b0
>> > 5 2 b1
>> > 6 3 b0
>> > 7 1 c1
>> > 8 2 c0
>> > 9 3 c0
>> >> as.matrix(test)
>> >z
>> > y   a b c
>> >   1 0 0 1
>> >   2 0 1 0
>> >   3 1 0 0
>> >> testm<-as.matrix(test)
>> >> testm
>> >z
>> > y   a b c
>> >   1 0 0 1
>> >   2 0 1 0
>> >   3 1 0 0
>> >> typeof(testm)
>> > [1] "integer"
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > 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 -- To UNSUBSCRIBE and more, see
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] Removing NAs from dataframe (for use in Vioplot)

2016-04-30 Thread David Winsemius

> On Apr 30, 2016, at 4:16 PM, David Winsemius  wrote:
> 
> 
>> On Apr 30, 2016, at 12:58 PM, Mike Smith  wrote:
>> 
>> Hi
>> 
>> First post and a relative R newbie
>> 
>> I am using the vioplot library to produce some violin plots.

It's a package,   not a library.

>> I have an input CSV with columns off irregular length that contain NAs. I 
>> want to strip the NAs out and produce a multiple violin plot automatically 
>> labelled using the headers. At the moment I do this
>> 
>> Code: 
>> ds1 = read.csv("http://www.lecturematerials.co.uk/data/spelling.csv;)
>> library(vioplot)
>> y6<-na.omit(ds1$y6)
>> y5<-na.omit(ds1$y5)
>> y4<-na.omit(ds1$y4)
>> y3<-na.omit(ds1$y3)
>> y2<-na.omit(ds1$y2)
>> y1<-na.omit(ds1$y1)
>> vioplot(y6, y5, y4,y3,y2,y1,horizontal=TRUE, names=c("Y6", 
>> "Y5","Y4","Y3","Y2","Y1"), col = "lightblue")
>> 
>> 
>> Two queries:
>> 
>> 1. Is there a more elegant way of automatically stripping the NAs, passing 
>> the columns to the function along with the header names??
>> 
> 
> ds2 <- lapply( ds1, na.omit)
> 
> 
>> 2. Can I easily add the sample size to each violin plotted??
> 
>> ?violplot
> No documentation for ‘violplot’ in specified packages and libraries:
> you could try ‘??violplot’

I see that I mispled that _package_ name. However, after loading it I realized 
that I had no way of replicating what you are seeing, because you didn't 
provide that file (or even something that resembles it. It's rather unclear how 
you wanted this information presented.

-- 
David.


David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Removing NAs from dataframe (for use in Vioplot)

2016-04-30 Thread David Winsemius

> On Apr 30, 2016, at 12:58 PM, Mike Smith  wrote:
> 
> Hi
> 
> First post and a relative R newbie
> 
> I am using the vioplot library to produce some violin plots. I have an input 
> CSV with columns off irregular length that contain NAs. I want to strip the 
> NAs out and produce a multiple violin plot automatically labelled using the 
> headers. At the moment I do this
> 
> Code: 
> ds1 = read.csv("http://www.lecturematerials.co.uk/data/spelling.csv;)
> library(vioplot)
> y6<-na.omit(ds1$y6)
> y5<-na.omit(ds1$y5)
> y4<-na.omit(ds1$y4)
> y3<-na.omit(ds1$y3)
> y2<-na.omit(ds1$y2)
> y1<-na.omit(ds1$y1)
> vioplot(y6, y5, y4,y3,y2,y1,horizontal=TRUE, names=c("Y6", 
> "Y5","Y4","Y3","Y2","Y1"), col = "lightblue")
> 
> 
> Two queries:
> 
> 1. Is there a more elegant way of automatically stripping the NAs, passing 
> the columns to the function along with the header names??
> 

ds2 <- lapply( ds1, na.omit)


> 2. Can I easily add the sample size to each violin plotted??

> ?violplot
No documentation for ‘violplot’ in specified packages and libraries:
you could try ‘??violplot’

> 


> thanks
> 
> mike
>   
> 
> 
> ---
> Mike Smith
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] CTree to obtain segmented data

2016-04-30 Thread Preetam Pal
Hi guys,

I have a dataset obtained as:
mydata <- read.csv("data.csv", header = TRUE) which contains the variable
'y' (y is binary 0 or 1) and some regressor variables.
I want to apply the ctree technique on this data with the following
requirements:
1> Of course I would need the tree plot (which I can do myself)
2> After that, I would need the segmented subsets of the data (as
determined by running ctree()) in array format, i.e. if ctree partitions
mydata into 6 smaller datasets, I need to output an array 'CTree_Subsets'
with 6 elements, each element being one of these smaller datasets. Note
that I need the actual smaller datasets in the array, and not just their
characteristics/classification rules obtained from the tree. (Context: I'll
need to run separate logistic regression models for each of these smaller
datasets). Would really appreciate your help with this issue

Thanks,
Preetam

-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Install R (version 3.2.5) in CentOS platform

2016-04-30 Thread wenbo
Hi,
I want to install the latest R in CentOS. Below is the command line:

./configure --prefix=/home/fino/R/3.2.5/
--with-tcl-config=/home/fino/software/tcl8.6.1/lib/tclConfig.sh
--with-tk-config=
/home/fino
/software/tk8.6.1/lib/tkConfig.sh --with-readline=yes
--with-cairo=yes --without-x

Below is the output message when ran the above command:
...
checking whether pkg-config knows about cairo and pango... no
checking whether pkg-config knows about cairo... yes
checking whether cairo is >= 1.2 and works... no
...

  C++ compiler:  g++  -g -O2
  C++ 11 compiler:   g++  -std=c++0x -g -O2
  Fortran 90/95 compiler:gfortran -g -O2
  Obj-C compiler:gcc -g -O2 -fobjc-exceptions

  Interfaces supported:  tcltk
  External libraries:readline, zlib, bzlib, lzma, PCRE
  Additional capabilities:   PNG, JPEG, TIFF, NLS
  Options enabled:   shared BLAS, R profiling

  Capabilities skipped:  cairo, ICU
  Options not enabled:   memory profiling

  Recommended packages:  yes

After I installed the R and entered R:
> capabilities()
   jpeg pngtiff   tcltk X11aqua
  FALSE   FALSE   FALSETRUE   FALSE   FALSE
   http/ftp sockets  libxmlfifo  cledit   iconv
   TRUETRUETRUETRUETRUETRUE
NLS profmem   cairo ICU long.double libcurl
   TRUE   FALSE   FALSE   FALSETRUE   FALSE

The png doesn't work. Does anyone know how to solve this problem?

Best regards!
Bo

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Removing NAs from dataframe (for use in Vioplot)

2016-04-30 Thread Mike Smith
Hi

First post and a relative R newbie

I am using the vioplot library to produce some violin plots. I have an input 
CSV with columns off irregular length that contain NAs. I want to strip the NAs 
out and produce a multiple violin plot automatically labelled using the 
headers. At the moment I do this

Code: 
ds1 = read.csv("http://www.lecturematerials.co.uk/data/spelling.csv;)
library(vioplot)
y6<-na.omit(ds1$y6)
y5<-na.omit(ds1$y5)
y4<-na.omit(ds1$y4)
y3<-na.omit(ds1$y3)
y2<-na.omit(ds1$y2)
y1<-na.omit(ds1$y1)
vioplot(y6, y5, y4,y3,y2,y1,horizontal=TRUE, names=c("Y6", 
"Y5","Y4","Y3","Y2","Y1"), col = "lightblue")


Two queries:

1. Is there a more elegant way of automatically stripping the NAs, passing the 
columns to the function along with the header names??

2. Can I easily add the sample size to each violin plotted??

thanks

mike



---
Mike Smith

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Data Issues with ctree/glm and controlling classification parameters

2016-04-30 Thread Preetam Pal
Hi,

I have a dataset obtained as:

mydata <- read.csv("data.csv", header = TRUE) which contains the variable
'y' (y is binary 0 or 1) and also another variable 'weight' (weight is a
numerical variable - taking fractional values between 0 and 1).

1>
I want to first apply ctree() on  mydata, but dont want to use this
'weight' variable in the tree-buiding process. Can you please suggest how
to do this? Please note, I *don't* want to delete/remove this variable from
mydata.


2>
Another question: Say, I split up mydata into train (80%) and test(20%) as:
d<-sort(sample(nrow(mydata), nrow(mydata)*0.8));
train <- mydata[d,];
test < -mydata[-d,];


Then, I perform weighted glm (essentially, logistic regression) on train as:
#Build GLM model on train data
model <-glm(y~., data = train, weights = train$weight, family = binomial);
(A)
#Apply model on test
score <-predict(model, type = 'response',test); **(B)
#Get classification for each observation in test as 'positive' or 'negative'
classify <-performance(score,"tpr","fpr"); **(C)

My question here is:
2a> Again, how do I proceed if I don't want to use the variable 'weight' as
a regressor in the glm() function in (A) above (but use all other variables
in train)?
2b> In step (B) & (C), how do I control the classification rule, i.e. R
might classify observations with model-fitted probability > 0.5 as a
'positive' and <= 0.5 as a 'negative'. Is there a way I can change this
threshold to say, 0.75 instead of whatever R might be using (I used 0.5 as
example).

Thank you in advance for your help.
-Preetam
-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 use AND in grepl

2016-04-30 Thread William Dunlap via R-help
Your code looks fine to me.  What did t2pd look like?

I tried reproducing the problem in R-3.2.4(Revised) and everything worked
(although the output of str() looked a bit different - perhaps you have an
old version of R)

> df <- data.frame(TE=1:10, TR=101:110,
Command=c("pd_local_abdomen_t2","knee_pd_t1_localize","PD_localize_tre_t2","t2_localize_PD")[rep(1:4,len=10)])
> str(df)
'data.frame':   10 obs. of  3 variables:
 $ TE : int  1 2 3 4 5 6 7 8 9 10
 $ TR : int  101 102 103 104 105 106 107 108 109 110
 $ Command: Factor w/ 4 levels "knee_pd_t1_localize",..: 2 1 3 4 2 1 3 4 2 1
> subset(df,grepl("t2",Command) & grepl("pd",Command))
  TE  TR Command
1  1 101 pd_local_abdomen_t2
5  5 105 pd_local_abdomen_t2
9  9 109 pd_local_abdomen_t2
> subset(df,grepl("t2",Command,ignore.case=TRUE) &
grepl("pd",Command,ignore.case=TRUE))
  TE  TR Command
1  1 101 pd_local_abdomen_t2
3  3 103  PD_localize_tre_t2
4  4 104  t2_localize_PD
5  5 105 pd_local_abdomen_t2
7  7 107  PD_localize_tre_t2
8  8 108  t2_localize_PD
9  9 109 pd_local_abdomen_t2


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help 
wrote:

> Hi all,
>
> I have one factor variable in my df and I want to extract the names from
> it which contain both "t2" and "pd":
>
>   'data.frame': 36919 obs. of 162 variables
>$TE:int 38,41,11,52,48,75,.
>$TR:int 100,210,548,546,.
>$Command  :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>
> I have tried this but I did not get result:
>
>   t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>
>
> does anyone know how to apply AND in grepl?
>
> Thanks
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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 use AND in grepl

2016-04-30 Thread ch.elahe via R-help
Hi all,

I have one factor variable in my df and I want to extract the names from it 
which contain both "t2" and "pd":

  'data.frame': 36919 obs. of 162 variables 
   $TE:int 38,41,11,52,48,75,. 
   $TR:int 100,210,548,546,. 
   $Command  :factor W/2229 levels 
"_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...

I have tried this but I did not get result: 
   
  t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))


does anyone know how to apply AND in grepl?

Thanks
Elahe

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 print the frequency table (produced by the command "table" to Excel

2016-04-30 Thread jpm miao
Jim,

   Thanks for creating such a fantastic package "prettyR".
   I want to print the pretty frequency table (with row total and column
total) to an excel (or csv ) file. Is it possible?
>alphatab

A B Total
A 8 10 18
B 7 5 12
C 9 11 20
Total 24 26 50

   Two issues I encountered (See the attached csv file).
1. When I tried to print the above table to csv file, all elements on the
same row are printed in one cell.
2. If I write "delim.table(alpha tab)", the table is distorted (see
attached). Of course, I can adjust it manually but sometimes the number of
files is big.

Thanks!

Miao

> alpha1<-sample(LETTERS[1:3],50,TRUE)
> alpha2<-sample(LETTERS[1:2],50,TRUE)
>
> alphas<-data.frame(alpha1,alpha2)
> alphatab<-xtab(alpha1~alpha2,alphas)
Crosstabulation of alpha1 by alpha2
alpha2
alpha1  A  B
A  8 10 18
   44.44  55.56  -
   33.33  38.46  36.00

B  7  5 12
   58.33  41.67  -
   29.17  19.23  24.00

C  9 11 20
  45 55  -
   37.50  42.31  40.00

  24 26 50
  48 52100
> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
alphatab

A B Total
A 8 10 18
B 7 5 12
C 9 11 20
Total 24 26 50

> sink("temp_table3.csv")
> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
> sink()
> sink("temp_table3.csv", append=TRUE)
> delim.table(alphatab)
> sink()
> sink("temp_table3.csv", append=TRUE)
> delim.table(alphatab)
> sink()
> ?delim.xtab


2016-04-26 16:14 GMT-07:00 Jim Lemon :

> Hi jpm miao,
> You can get CSV files that can be imported into Excel like this:
>
> library(prettyR)
> sink("excel_table1.csv")
> delim.table(table(df[,c("y","z")]))
> sink()
> sink("excel_table2.csv")
> delim.table(as.data.frame(table(df[,c("y","z")])),label="")
> sink()
> sink("excel_table3.csv")
> delim.table(as.matrix(table(df[,c("y","z")])),label="")
> sink()
>
> Jim
>
> On Wed, Apr 27, 2016 at 8:35 AM, jpm miao  wrote:
> > Hi,
> >
> >How could we print the frequency table (produced by "table") to an
> Excel
> > file?
> >Is there an easy way to do so? Thanks,
> >
> > Miao
> >
> >> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3])
> >
> >> table(df[,c("y","z")])
> >z
> > y   a b c
> >   1 0 0 1
> >   2 0 1 0
> >   3 1 0 0
> >> test<-table(df[,c("y","z")])
> >> as.data.frame(test)
> >   y z Freq
> > 1 1 a0
> > 2 2 a0
> > 3 3 a1
> > 4 1 b0
> > 5 2 b1
> > 6 3 b0
> > 7 1 c1
> > 8 2 c0
> > 9 3 c0
> >> as.matrix(test)
> >z
> > y   a b c
> >   1 0 0 1
> >   2 0 1 0
> >   3 1 0 0
> >> testm<-as.matrix(test)
> >> testm
> >z
> > y   a b c
> >   1 0 0 1
> >   2 0 1 0
> >   3 1 0 0
> >> typeof(testm)
> > [1] "integer"
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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 -- To UNSUBSCRIBE and more, see
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] 3D surface plot

2016-04-30 Thread Bert Gunter
There are several packages and functions that can do this (e.g. search
on "3d surface plots" at rseek.org or internet search engine).

You are much more likely to get a helpful answer if you provide a
minimal data set (e.g. via dput() ) and code from any function(s) and
package(s) that you tried. A pdf with a formula in it is not very
r-helper friendly.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Apr 30, 2016 at 10:48 AM, T.Riedle  wrote:
> Dear R users,
>
> I am trying to generate a 3D surface plot given the inflator formula in the 
> attached file.
>
> Now, I want to create a 3D plot showing how Delta changes with the values of 
> Abs(B) and sigma. The other variables in the formula are constant. Delta is 
> calculated daily therefore the subscript t which denotes the day. I have used 
> different functions and different packages but I get either wrong results or 
> an error in R.
>
> Does anyone have an idea which function I should use?
>
> Furthermore, I think I have to create a matrix using the formula above but I 
> do not know how to do that in this connection. Can any body help me with the 
> code for this purpose?
>
> Thanks a lot in advance.
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] 3D surface plot

2016-04-30 Thread T.Riedle
Dear R users,

I am trying to generate a 3D surface plot given the inflator formula in the 
attached file.

Now, I want to create a 3D plot showing how Delta changes with the values of 
Abs(B) and sigma. The other variables in the formula are constant. Delta is 
calculated daily therefore the subscript t which denotes the day. I have used 
different functions and different packages but I get either wrong results or an 
error in R.

Does anyone have an idea which function I should use?

Furthermore, I think I have to create a matrix using the formula above but I do 
not know how to do that in this connection. Can any body help me with the code 
for this purpose?

Thanks a lot in advance.



buvar_countercyclical_capital_buffer_17_1419139702[1].pdf
Description: buvar_countercyclical_capital_buffer_17_1419139702[1].pdf
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] selection columns by type, ie, numeric

2016-04-30 Thread Ranjan Maitra
It would have been more useful to the list and to posterity if you had 
summarized whatever it was that worked or solved your problem. This note is not 
very meaningful otherwise.

On Sat, 30 Apr 2016 16:00:10 + (UTC) Carl Sutton via R-help 
 wrote:

> My  thanks to Bill Dunlap and  Giorgio Garziano for  their help.   It is 
> greatly appreciated.  I works so well, wow.
> Carl Sutton CPA
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Important Notice: This mailbox is ignored: e-mails are set to be deleted on 
receipt. Please respond to the mailing list if appropriate. For those needing 
to send personal or professional e-mail, please use appropriate addresses.


Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] selection columns by type, ie, numeric

2016-04-30 Thread Carl Sutton via R-help
My  thanks to Bill Dunlap and  Giorgio Garziano for  their help.   It is 
greatly appreciated.  I works so well, wow.
Carl Sutton CPA

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Graphlet degree distribution agreement in

2016-04-30 Thread seema aswani
Hi all,

I have created my network using igraph package. It provides graphlet
function to calculate number of graphltes. I want to find graphlet degree
distribution agreement of a graph. How can i achieve that..??
The package ergm.graphlets is there in r but there isn't any examples
available for usage of this package.

My R script is:

library(igraph)
g2 <- graph.formula(A:B - A:C, X:Z - X:Y - X:B, C:Z , C:X )
g2
plot(g2)

Please provide help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Could not find function "pointsToRaster"

2016-04-30 Thread Ogbos Okike
Dear All,
Thanks for your inputs. I did replace pointsToRaster () with
raster::rasterize(). Below is part of my script.

But I got another error:
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘rasterize’ for
signature ‘"RasterLayer", "matrix"’

Thank you for more inputs.
Ogbos

 k<-read.table("Lat05w3.txt")
 colnames(k)<-c("y","x")
 xy<-cbind(k$x,k$y)
 library(raster)
 r<-raster()
#library(sp)
pr<-raster::rasterize(r,xy)

#pr<-pointsToRaster(r,xy)

library(maps)
w = map("world")
 wc = cbind(w$x, w$y)
 wc=wc[!is.na(wc[,1]),]
 write.table(wc, file = "my.fileb", sep=" ",row=FALSE,col=FALSE)
 my<-read.table("my.out",col.names=c("a","b"))
 rena = function(X,Z){
Y=rep(NA,length(X))
Y[!is.na(X)]=Z
Y
}




On 4/30/16, Ben Tupper  wrote:
> Hi,
>
> A terrific resource for this type of issue (and pretty much anything related
> to R) is http://rseek.org/  I'm sure I use it at least daily.  Check out
> ...
>
> http://rseek.org/?q=pointsToRaster
>
> The first hit is about pointsToRaster() - it has been replaced by
> raster::rasterize()
>
> Cheers,
> Ben
>
>> On Apr 30, 2016, at 4:28 AM, Ogbos Okike 
>> wrote:
>>
>> Dear All,
>> I have a script that draws longitude and latitude of lightning
>> occurrence. This script was running fine before. But when I changed my
>> system and do a fresh install on another laptop, this error persist.
>> source("script")
>> Error in eval(expr, envir, enclos) :
>>  could not find function "pointsToRaster"
>>
>> I have tried to see if  there is any other package I need to install
>> to take of the problem, I could not see. Already, when I installed
>> raster, it installed its dependencies such as sp.
>> Can any body please bail me out.
>>
>> Thanks
>> Ogbos
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] tcltk: click and return table cell index

2016-04-30 Thread Fox, John
Dear Daniel,

Try 

tkbind(table1, "", function(){
 res <- try(tclvalue(tkindex(table1, "active")), silent=TRUE)
   if (inherits(res, "try-error")) print (NULL)
   else print(res)
})

I put in the calls to print() so that you could see how it works.

I hope this helps,
 John

-
John Fox, Professor
McMaster University
Hamilton, Ontario
Canada L8S 4M4
Web: socserv.mcmaster.ca/jfox


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
> Daniel
> Sent: April 29, 2016 1:42 PM
> To: r-help@R-project.org (r-help@r-project.org) 
> Subject: [R] tcltk: click and return table cell index
> 
> I'm struggling mightily with what should be a simple task...when a user clicks
> on a cell in a tcltk table widget, I need to know which cell was clicked.
> 
> One idea that gives a cryptic error:
> tkbind(table1, "", function(x, y){
>   tcl(table1, "index", x, y)
> }
> 
> # x, y give pixel coordinates; "index" should give cell coordinates, but 
> format
> must be correct
> 
> I get an error message:
> 
> wrong # args: should be ".25.1 index  ?row|col?".
> 
> To which I respond, "Yes, I know I have the format wrong, but how can I make
> sense of THAT?"
> 
> Does anyone know a simple fix?
> 
> Much appreciated!
> 
> -Dan
> 
> --
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center Forest Sciences Lab, Rm
> 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalth...@usgs.gov
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] Package to work with weight based data

2016-04-30 Thread Joao Sollari Lopes
Hi Biswajit Kar,

Take a look at this CRAN Task:
https://cran.r-project.org/web/views/OfficialStatistics.html

Also, I've been re-writing functions of package "ineq" so that they 
accept weights. I can provide those if you find them useful.
Finally, there are a bunch of packages in CRAN that provide plottings 
using weights (e.g. "weights", "Hmisc", "ENmisc", ...)

Joao

On 30-04-2016 11:00, r-help-requ...@r-project.org wrote:
> Date: Fri, 29 Apr 2016 13:31:43 +
> From: "Federman, Douglas"
> To: "'BISWAJIT KAR'","R-help@r-project.org"
>   
> Subject: Re: [R] Package to work with weight based data
> Message-ID:
>   
> Content-Type: text/plain; charset="us-ascii"
>
> You might look at Anthony D'Amico's work at
>
>  Asdfree.com
>
> There is a lot to learn from here and many of those examples work with 
> weighted survey results
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of BISWAJIT KAR
> Sent: Thursday, April 28, 2016 12:32 PM
> To:R-help@r-project.org
> Subject: [R] Package to work with weight based data
>
> Respected all,
>  I am working on a socio-economic survey (named as
> National Sample Survey in India provided by National Sample Survey
> Organization, Govt. of India) data of individual as well as households.
> This is a sample survey where stratified random sapling method has been
> used to draw samples. The data set uses 'weights' to estimate figures for
> region, state or country level. In the data set, there is a variable called
> weights and I use the *'weight cases'* function to activate weights
> under *'Data'
>   option *in menu bar in SPSS before generating any table or doing any
> statistical procedure. So, my question is, is there any package/s in R
> where I can use weights and work on this kind of sample survey.
>
> Second thing, is there any package/s to generate multi layer contingency
> table in R or how can I do this in R. For example, one similar kind of
> table is attached here which one is created by SPSS from the above stated
> data-set. Please have a look.
> -- Thanks, *Biswajit Kar* (Research Scholar) Ph. D. Student, Geography 
> Centre for the Study of Regional Development School of Social Sciences 
> Jawaharala Nehru University New Delhi-110067 
> __ R-help@r-project.org 
> mailing list -- To UNSUBSCRIBE and more, see 
> 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 -- To UNSUBSCRIBE and more, see
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] Declaring All Variables as Factors in GLM()

2016-04-30 Thread Leonardo Ferreira Fontenelle
This should do the trick:

history2 <- as.data.frame(lapply(history, as.factor))

Mind you that read.csv() by default reads string vectors as factors, so
that declaring the variables as factors should only be necessary for the
numeric ones, like income. Using as.factor() in factor variables may
drop unused levels, but in your case I believe it won't be a problem.

HTH,

Leonardo Ferreira Fontenelle
http://lattes.cnpq.br/9234772336296638

Em Sáb 30 abr. 2016, às 04:25, Preetam Pal escreveu:
> Hi guys,
> 
> I am running glm(y~., data = history,family=binomial)-essentially,
> logistic
> regression for credit scoring (y = 0 or 1). The dataset 'history' has 14
> variables, a few examples:
> history <- read.csv("history.csv". header = TRUE)
> 1> 'income = 100,200,300 (these are numbers in my dataset; however
> interpretation is that these are just tags or labels,for every
> observation,
> its income gets assigned one of these tags)
> 2> 'job' = 'private','government','unemployed','student'
> 
> I want to declare all the regressors and y variables *as factors*
> programmatically. Would be great if anyone can help me with this (idea is
> to loop over variable names and use as.factor - but not sure how to do
> this). Thanks
> 
> Regards,
> Preetam
> -- 
> Preetam Pal
> (+91)-9432212774
> M-Stat 2nd Year, Room No.
> N-114
> Statistics Division,   C.V.Raman
> Hall
> Indian Statistical Institute, B.H.O.S.
> Kolkata.
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] Unexpected scores from weighted PCA with svyprcomp()

2016-04-30 Thread Leonardo Ferreira Fontenelle
Hello!

I'd like to create an assets-based economic indicator using data from a
national household survey. The economic indicator is to be the first
principal component from a principal components analysis, which (given
the source of the data) I believe should take in consideration the
sampling weights of the observations. After running the PCA with
svyprcomp(), from the survey package, I wanted to list the loading (with
regard to the first principal component) and the scale of the variables,
so that I can tell people how to "reconstitute" the economic indicator
from the variables without any knowledge of PCA. This reconstituted
indicator wouldn't be centered, but that's OK because the important
thing for the application is the relative position of the observations.
The unexpected (at least for me) behavior was that the principal
component returned by svyprcomp() was very different from from the
reconstituted indicator as well as from the indicator returned by
predict(). "Different" here means weak correlation and different
distributions.

I hope the following code illustrates what I mean:

=

svycor <- function(formula, design) {
  # https://stat.ethz.ch/pipermail/r-help/2003-July/036645.html
  stopifnot(require(survey))
  covariance.matrix <- svyvar(formula, design)
  variables <- diag(covariance.matrix)
  correlation.matrix <- covariance.matrix / sqrt(variables %*%
  t(variables))
  return(correlation.matrix)
}

library(survey)
data(api)
dclus2 <- svydesign(ids = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data =
apiclus2)
pc <- svyprcomp( ~ api99 + api00, design = dclus2, scale = TRUE, scores
= TRUE)
dclus2$variables$pc1 <- pc$x[, "PC1"]
dclus2$variables$pc2 <- predict(pc, apiclus2)[, "PC1"]
mycoef <- pc$rotation[, "PC1"] / pc$scale
dclus2$variables$pc3 <- with(apiclus2, api99 * mycoef["api99"] + api00 *
mycoef["api00"])
svycor(~ pc1 + pc2 + pc3, dclus2)[, ]
#   pc1   pc2   pc3
# pc1 1.000 0.2078789 0.2078789
# pc2 0.2078789 1.000 1.000
# pc3 0.2078789 1.000 1.000
plot(svysmooth(~ pc1, dclus2), xlim = c(-2.5, 5), ylim = 0:1)
lines(svysmooth(~ pc2, dclus2), col = 2)
lines(svysmooth(~ pc3, dclus2), col = 3)
legend("topright", legend = c('pc$x[, "PC1"]', 'predict(pc, apiclus2)[,
"PC1"]', 'Reconstituted indicator'), col = 1:3, lty = 1)

sessionInfo()
# R version 3.2.4 Revised (2016-03-16 r70336)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Arch Linux
# 
#  locale:
#  [1] LC_CTYPE=pt_BR.UTF-8   LC_NUMERIC=C  
#  [3] LC_TIME=pt_BR.UTF-8LC_COLLATE=pt_BR.UTF-8
#  [5] LC_MONETARY=pt_BR.UTF-8LC_MESSAGES=pt_BR.UTF-8   
#  [7] LC_PAPER=pt_BR.UTF-8   LC_NAME=C 
#  [9] LC_ADDRESS=C   LC_TELEPHONE=C
# [11] LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C   
# 
# attached base packages:
# [1] grid  stats graphics  utils datasets  grDevices
# [7] methods   base 
# 
# other attached packages:
# [1] KernSmooth_2.23-15 survey_3.30-3 
# 
# loaded via a namespace (and not attached):
# [1] tools_3.2.4

=

This lack of correlation doesn't happen if the survey design object has
uniform sampling weights or if the the data is analyzed with prcomp().

Why does the returned principal component is so different from the
predicted and the reconstituted ones? Are predict() and my
"reconstitution" missing something? Are the three methods equally valid
but with different interpretations? Is there a bug in svyprcomp() ??

Thanks in advance,

Leonardo Ferreira Fontenelle
http://lattes.cnpq.br/9234772336296638

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Could not find function "pointsToRaster"

2016-04-30 Thread Leonardo Ferreira Fontenelle
Dear Ogbos Okike,

I can't know how your script depends on pointsToRaster(), but googling
around I found that the function seems to have been marked as obsolete:

http://www.inside-r.org/packages/cran/raster/docs/linesToRaste

Hope that helps,

Leonardo Ferreira Fontenelle
http://lattes.cnpq.br/9234772336296638

Em Sáb 30 abr. 2016, às 05:28, Ogbos Okike escreveu:
> Dear All,
> I have a script that draws longitude and latitude of lightning
> occurrence. This script was running fine before. But when I changed my
> system and do a fresh install on another laptop, this error persist.
>  source("script")
> Error in eval(expr, envir, enclos) :
>   could not find function "pointsToRaster"
> 
> I have tried to see if  there is any other package I need to install
> to take of the problem, I could not see. Already, when I installed
> raster, it installed its dependencies such as sp.
> Can any body please bail me out.
> 
> Thanks
> Ogbos
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] Could not find function "pointsToRaster"

2016-04-30 Thread Ben Tupper
Hi,

A terrific resource for this type of issue (and pretty much anything related to 
R) is http://rseek.org/  I'm sure I use it at least daily.  Check out ...

http://rseek.org/?q=pointsToRaster

The first hit is about pointsToRaster() - it has been replaced by 
raster::rasterize()

Cheers,
Ben

> On Apr 30, 2016, at 4:28 AM, Ogbos Okike  wrote:
> 
> Dear All,
> I have a script that draws longitude and latitude of lightning
> occurrence. This script was running fine before. But when I changed my
> system and do a fresh install on another laptop, this error persist.
> source("script")
> Error in eval(expr, envir, enclos) :
>  could not find function "pointsToRaster"
> 
> I have tried to see if  there is any other package I need to install
> to take of the problem, I could not see. Already, when I installed
> raster, it installed its dependencies such as sp.
> Can any body please bail me out.
> 
> Thanks
> Ogbos
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-es] Mapas de vitoriaen R

2016-04-30 Thread Jesús Para Fernández
Buenas, 
�Qu� paquete de todos los que hay para graficar sobre mapas me recomendais para 
graficar sobre los codigos postales de la ciudad de Vitoria Gasteiz?
GraciasJes�s  
[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

[R] Issue installing packages - Linux

2016-04-30 Thread Lars Bishop
Hello,

I can’t seem to be able to install packages on a redhat-linux-gnu. For
instance, this is what happens when I try to install “bitops”. Any hint on
what might be the issue would be much appreciated.

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

> Sys.setenv(https_proxy="https://labproxy.com:8080;)
> install.packages("bitops", lib="mypath ")

Here I choose: 22: (HTTP mirrors) and then a mirror 16:Canada(ON)

* installing *source* package âbitopsâ ...
** package âbitopsâ successfully unpacked and MD5 sums checked
Error in readRDS(pfile) : error reading from connection
ERROR: lazy loading failed for package âbitopsâ

I’ve also tried from the shell (after downloading the package source)

$  R CMD INSTALL bitops_1.0-6.tar.gz
ERROR: cannot extract package from bitops_1.0-6.tar.gz

Thank you,
Lars.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Could not find function "pointsToRaster"

2016-04-30 Thread Ogbos Okike
Dear All,
I have a script that draws longitude and latitude of lightning
occurrence. This script was running fine before. But when I changed my
system and do a fresh install on another laptop, this error persist.
 source("script")
Error in eval(expr, envir, enclos) :
  could not find function "pointsToRaster"

I have tried to see if  there is any other package I need to install
to take of the problem, I could not see. Already, when I installed
raster, it installed its dependencies such as sp.
Can any body please bail me out.

Thanks
Ogbos

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Declaring All Variables as Factors in GLM()

2016-04-30 Thread Preetam Pal
Hi guys,

I am running glm(y~., data = history,family=binomial)-essentially, logistic
regression for credit scoring (y = 0 or 1). The dataset 'history' has 14
variables, a few examples:
history <- read.csv("history.csv". header = TRUE)
1> 'income = 100,200,300 (these are numbers in my dataset; however
interpretation is that these are just tags or labels,for every observation,
its income gets assigned one of these tags)
2> 'job' = 'private','government','unemployed','student'

I want to declare all the regressors and y variables *as factors*
programmatically. Would be great if anyone can help me with this (idea is
to loop over variable names and use as.factor - but not sure how to do
this). Thanks

Regards,
Preetam
-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.