Re: [R] How to combine two rows in a data table into a third new row, such that the values in the row are added together in the new row?

2020-05-06 Thread K. Elo
Hi!

With 'dplyr':

dt_count %>% mutate(STATUS=ifelse(STATUS %in%
c("Resolved","Closed"),"Resolved/Closed",STATUS)) %>% group_by(STATUS)
%>% summarise(n=sum(N))

Output:

1 Assigned  135
2 Cancelled  20
3 In Progress56
4 Pending75
5 Resolved/Closed  1180

HTH,
Kimmo

2020-05-06, 04:41 +, Gregg via R-help wrote:
> If I have a data table that is essentially output titled: "dt_count"
> - it contains:
> 
> "","STATUS","N"
> "1","Resolved",650
> "2","Assigned",135
> "3","Closed",530
> "4","In Progress",56
> "5","Pending",75
> "6","Cancelled",20
> 
> Need to change the "dt_count" data table to a new data table that
> looks like this:
> 
> "","STATUS","N"
> "1","Resolved/Closed",1180
> "2","Assigned",135
> "3","In Progress",56
> "4","Pending",75
> "5","Cancelled",20
> 
> Or, to state the question:
> 
> I need to combine the "Resolved" Row with the "Closed" Row, into a
> Third new row titled "Resolved/Closed", whereby the "N" ticket count
> in each of the "Resolved" row and the "Closed" row are added together
> in the third new "Resolved/Closed" - also, would need the
> old "Resolved" Row with the "Closed" Rows to go away.
> 
> To complicate the issue, the rows in the "dt_count" data table when
> they are output, are not always in the same order.
> 
> I have the data.table library is installed.
> 
> I'm thinking there is a very easy way to do this... but I am not
> finding it. I've search thru several data table cheatsheets, and I've
> also read thru this:
> 
https://cran.r-project.org/web/packages/data.table/vignettes/datatable-intro.html
> 
> Just can't sort it out. Just started using R a few weeks ago.
> 
> Any help would be so very much appreciated!
> 
> Thanks.
> 
> Gregg
> AZ, 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-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] TWITTER API environment variables

2020-04-08 Thread K. Elo
Hi again,

ok, I see. How about repeating the steps described in the tutorial on
your second computer instead of cloning the settings from the computer
#1? There might be some other settings not correctly copied.

HTH,
Kimmo

ke, 2020-04-08 kello 19:02 +1200, Patrick Connolly kirjoitti:
> Hello Kimmo,
> 
> Yes.  I did that and it worked fine -- as far as it goes.  But it
> didn't cover what to do when using the same twitter account on a
> computer with a different user name -- which is what my question was
> about.
> 
> 
> On Wed, 08-Apr-2020 at 08:55AM +0300, K. Elo wrote:
> 
> > > Hi!
> > > 
> > > Have you already read this:
> > > 
> > > 
https://cran.r-project.org/web/packages/rtweet/vignettes/auth.html
> > > 
> > > I think they explain rather well how to use Twitter tokens with
> > > rtweet...
> > > 
> > > HTH,
> > > Kimmo
> > > 
> > > ke, 2020-04-08 kello 17:19 +1200, Patrick Connolly kirjoitti:
> > > > I'm using the rtweet package which makes use of the Twitter API
> > > > which
> > > > requires a token alluded to by an environment variable.
> > > > 
> > > > That environment variable is automatically set up from the
> > > > Twitter
> > > > web
> > > > site and takes the name TWITTER_ (where  is
> > > > the
> > > > name of the user in block letters).  That worked fine on my
> > > > work
> > > > computer where my username is 'work'.  When I copied that
> > > > working
> > > > directory to my home computer, the environment variable became
> > > > TWITTER_HOME but the rtweet package was looking for
> > > > TWITTER_WORK. There was no error message: just a null result
> > > > from the
> > > > search_users() function.
> > > > 
> > > > I tried editing the ~/.Renviron entry to
> > > > TWITTER_WORK=/home/home/.rtweet_token.rds
> > > > 
> > > > That worked for a short time but soon ceased working.  Then I
> > > > noticed
> > > > a new entry had been automatically added to ~/.Renviron
> > > > 
> > > > TWITTER_HOME=/home/home/.rtweet_token1.rds
> > > > 
> > > > So now I had two environment variables which also worked for a
> > > > short
> > > > time.
> > > > 
> > > > Recommendations please.
> > > > 
> > > 
> > > __
> > > 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] TWITTER API environment variables

2020-04-07 Thread K. Elo
Hi!

Have you already read this:

https://cran.r-project.org/web/packages/rtweet/vignettes/auth.html

I think they explain rather well how to use Twitter tokens with
rtweet...

HTH,
Kimmo

ke, 2020-04-08 kello 17:19 +1200, Patrick Connolly kirjoitti:
> I'm using the rtweet package which makes use of the Twitter API which
> requires a token alluded to by an environment variable.
> 
> That environment variable is automatically set up from the Twitter
> web
> site and takes the name TWITTER_ (where  is the
> name of the user in block letters).  That worked fine on my work
> computer where my username is 'work'.  When I copied that working
> directory to my home computer, the environment variable became
> TWITTER_HOME but the rtweet package was looking for
> TWITTER_WORK. There was no error message: just a null result from the
> search_users() function.
> 
> I tried editing the ~/.Renviron entry to
> TWITTER_WORK=/home/home/.rtweet_token.rds
> 
> That worked for a short time but soon ceased working.  Then I noticed
> a new entry had been automatically added to ~/.Renviron
> 
> TWITTER_HOME=/home/home/.rtweet_token1.rds
> 
> So now I had two environment variables which also worked for a short
> time.
> 
> Recommendations please.
>

__
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 extract or sort values from one column

2020-01-31 Thread K. Elo
Hi!

To extract full rows, use:

df[ ( (df$Value>=0.2 & df$Value<=0.4) | df$Value>=0.7 ), ]


But it is also a good idea to start reading some introductory
tutorials. These are basic things you can find in all tutorials :-)

Best,
Kimmo

pe, 2020-01-31 kello 10:50 -0500, pooja sinha kirjoitti:
> Thanks for providing the code but I also needed the output sheet in
> .csv format with all the four columns corresponding to the value
> (Chrom,
> Start_pos, End_pos & Value ranging from what I specified earlier).
> 
> Puja
> 
> On Fri, Jan 31, 2020 at 10:23 AM K. Elo  wrote:
> 
> > Hi!
> > 
> > Oh, sorry, one "s" too much in my code. Here the correct one:
> > 
> > df$Value[ (df$Value>=0.2 & df$Value<=0.4) | df$Value>=0.7 ]
> > 
> > Best,
> > Kimmo
> > 
> > pe, 2020-01-31 kello 17:12 +0200, K. Elo kirjoitti:
> > > Hi!
> > > 
> > > Let's assume your data is stored in a data frame called 'df'. So
> > > this
> > > code should do the job:
> > > 
> > > df$Value[ (df$Value>=0.2 & df$Values<=0.4) | df$Value>=0.7 ]
> > > 
> > > Best,
> > > Kimmo
> > > 
> > > 
> > > 
> > > pe, 2020-01-31 kello 09:21 -0500, pooja sinha kirjoitti:
> > > > Hi All,
> > > > 
> > > > I have a .csv file with four columns (Chrom, Start_pos, End_pos
> > > > &
> > > > Value).
> > > > The value column range from 0 to 1.0 having more than 2.8
> > > > million
> > > > rows. I
> > > > need to write a code from which I can extract the values from
> > > > 0.2-
> > > > 0.4
> > > > &
> > > > 0.7-1.0. Could anyone help me in writing the code because I am
> > > > new
> > > > to
> > > > R and
> > > > it takes lot of time manually to sort based on values.
> > > > 
> > > > The only part I know is I can read the .csv file and after that
> > > > I
> > > > don’t
> > > > know how to proceed further.
> > > > 
> > > > 
> > > > Thanks,
> > > > 
> > > > Puja
> > > > 
> > > > [[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-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 extract or sort values from one column

2020-01-31 Thread K. Elo
Hi!

Oh, sorry, one "s" too much in my code. Here the correct one:

df$Value[ (df$Value>=0.2 & df$Value<=0.4) | df$Value>=0.7 ]

Best,
Kimmo

pe, 2020-01-31 kello 17:12 +0200, K. Elo kirjoitti:
> Hi!
> 
> Let's assume your data is stored in a data frame called 'df'. So this
> code should do the job:
> 
> df$Value[ (df$Value>=0.2 & df$Values<=0.4) | df$Value>=0.7 ]
> 
> Best,
> Kimmo
> 
> 
> 
> pe, 2020-01-31 kello 09:21 -0500, pooja sinha kirjoitti:
> > Hi All,
> > 
> > I have a .csv file with four columns (Chrom, Start_pos, End_pos &
> > Value).
> > The value column range from 0 to 1.0 having more than 2.8 million
> > rows. I
> > need to write a code from which I can extract the values from 0.2-
> > 0.4 
> > &
> > 0.7-1.0. Could anyone help me in writing the code because I am new
> > to
> > R and
> > it takes lot of time manually to sort based on values.
> > 
> > The only part I know is I can read the .csv file and after that I
> > don’t
> > know how to proceed further.
> > 
> > 
> > Thanks,
> > 
> > Puja
> > 
> > [[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-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 extract or sort values from one column

2020-01-31 Thread K. Elo
Hi!

Let's assume your data is stored in a data frame called 'df'. So this
code should do the job:

df$Value[ (df$Value>=0.2 & df$Values<=0.4) | df$Value>=0.7 ]

Best,
Kimmo



pe, 2020-01-31 kello 09:21 -0500, pooja sinha kirjoitti:
> Hi All,
> 
> I have a .csv file with four columns (Chrom, Start_pos, End_pos &
> Value).
> The value column range from 0 to 1.0 having more than 2.8 million
> rows. I
> need to write a code from which I can extract the values from 0.2-0.4 
> &
> 0.7-1.0. Could anyone help me in writing the code because I am new to
> R and
> it takes lot of time manually to sort based on values.
> 
> The only part I know is I can read the .csv file and after that I
> don’t
> know how to proceed further.
> 
> 
> Thanks,
> 
> Puja
> 
>   [[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] Strange behaviour of R?

2020-01-17 Thread K. Elo
Hi,

cannot reproduce, either, on my Linuxmint 19.3 + R 3.6.2.

Here the outputs:

--- snip ---

> test(mean, 1:10)
[1] 5.5
> test(NULL, 1:10)
NULL
Error in FUN(args) : could not find function "FUN"
> test(mean, list(x=1:10, na.rm=TRUE))
[1] NA
Warning message:
In mean.default(args) : argument is not numeric or logical: returning
NA

--- snip ---

Best,
Kimmo

pe, 2020-01-17 kello 09:21 +0100, Sigbert Klinke kirjoitti:
> Hi,
> 
> Am 17.01.20 um 08:42 schrieb Rainer M Krug:
>  > Not for me - macOS, R 3.6.2
> 
> Sorry, I forgot to add: Ubuntu 18.04.3 LTS, R 3.6.2
> 
> Best Sigbert
>

__
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] Required help

2019-05-06 Thread K. Elo
Hi Rajesh,

2019-05-05 10:23 +0530, Rajesh Ahir_GJ wrote:
> Hello R users,
> 
> I am getting an error while running following code.
> 
> library(ggplot2)
> ggplot(hourly_data1,aes(hour, power))+
> geom_boxplot(aes(fill=monthname),outlier.shape=NA) +
> facet_wrap(~monthname)
> ggplot(hourly_data1,aes(hour, power))+
> geom_boxplot(aes(fill=dayname),outlier.shape=NA) +
> facet_wrap(~dayname) +
> geom_smooth(aes(group=1))
> 
> An error i am getting is:
> Error: Must request at least one colour from a hue palette.
> 
> Please help me to solve this.

1) A sample data would be nice, it is hard to debug without proper data
:-)

2) One thing you could check: is there any NAs in you data, i.e. in the
variable used for 'fill'? Check this first.

3) You have two 'ggplot' commands in your example. Do you get the error
for both or just for one?

Best,
Kimmo

__
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] what would break a citation network? [Error in as.igraph.vs(graph, vids) : Invalid vertex names]

2019-05-04 Thread K. Elo
Hi Drake,

2019-05-04, 17:34 -0700, Drake Gossi wrote:
> Hello everyone,
> 
> I'm trying to learn how to put together a citation network, and, in
> doing so, I'm playing around with a data set of my own making. I'm
> going back and forth between two .csv files. One has two columns and
> is simply labeled "to" and "from":
> 
> to from
> rickert heidegger
> rickert nietzsche
> rickert parmenides
> rickert diogenes
> rickert latour
> rickert haraway
> rickert barad
> rickert burke
> boyle mackenzie
> boyle flusser
> boyle kittler
> boyle massumi
> boyle mattern
> boyle rickert
> boyle berlant
> boyle ulmer
> boyle manovich
> boyle burke
> 
> So, rickert and boyle are academics, and the people to the right are
> other scholars they cite. This one .csv file goes on for 75 rows like
> this.
> 
> But I have another file too, which looks like this. The two columns
> are "author" and "association":
> 
> author association
> latour STS
> burke rhetoric
> kittler media theory
> heidegger philosophy
> barthes philosophy
> mackenzie media theory
> massumi affect theory
> nietzsche philosophy
> flusser media theory
> rickert rhetoric
> spinuzzi tech comm
> boyle rhetoric
> gries rhetoric
> jeff rice rhetoric
> jenny rice rhetoric
> gunn rhetoric
> rivers rhetoric
> mol STS
> stengers STS
> barad STS
> braidotti posthumanism
> wolfe posthumanism
> haraway STS
> 
> The trouble is, when I add the following (davis, rhetoric) onto the
> second list, the citation network breaks.
> 
> ...
> ...
> braidotti posthumanism
> wolfe posthumanism
> haraway STS
> davis rhetoric
> 
> My question is: why would the addition of a single row break the
> analysis? I am getting this error message:
> 
> Error in as.igraph.vs(graph, vids) : Invalid vertex names
> 
> My code is this:
> 
> install.packages("igraph")
> library(igraph)
> myEdgeList <- as.matrix(read.csv("myEdgeList.csv", as.is=TRUE))
> G <- graph.edgelist(myEdgeList, directed=FALSE)
> myThemes <- read.csv("myThemes.csv", as.is=TRUE)
> rowNumberofMatchingCases <- which(myThemes$association %in%
> c("rhetoric"
>   ))
> authorsOfMatchingCases <- myThemes$author [rowNumberofMatchingCases]
> H <- induced.subgraph (G, authorsOfMatchingCases)
> lout <- layout.fruchterman.reingold(H)
> plot.igraph(H, layout=lout, vertex.size=5, vertex.label.cex=.5)
> 
> My guess is I have broken some fundamental rule of graphing, like one
> of the names performs too many functions in the graph, or I have
> "rhetoric" too many times in the is the second csv file...
> 
> But I really think the better question is: if you were just fooling
> around and trying to make a citation network from hand and by
> scratch,
> like I'm doing, what could you not do with the list? and does this
> have something to do with transitivity?
> 
> Drake

With "davis" you try to refer to a vertex (node) not existing in your
vertex list. This results in an error.

Take a look on this, if I understood your problem correctly it is a
similar issue:


https://stackoverflow.com/questions/30201510/error-with-subgraph-in-igraph-package

HTH,
Kimmo

__
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] Printing vectrix

2019-03-25 Thread K. Elo
Hi!

2019-03-25 kello 09:30 +0800, Steven Yen wrote:
> The second command is ugly. How can I print the 25 numbers into 2
> rows 
> of ten plus a helf row of 5? Thanks.

Something like this?

x<-1:25; for (i in seq(1,length(x),10))
print(x[i:ifelse((i+9)>length(x),length(x),i+9)])

HTH,
Kimmo

__
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] color question

2019-02-27 Thread K. Elo
Hi!

2019-02-27 22:51 -0500, Aimin Yan wrote:
> I have a question about assigning color based on the value of a
> matrix
> 
> The following is my matrix.
> 
> d
>  lateRT  earlyRT NAD   ciLAD
> lateRT  1.0 0.00 0.006224017 0.001260241
> earlyRT 0.0 1.00 0.001425649 0.007418436
> NAD 0.006224017 0.0014256488 1.0 0.064653780
> ciLAD   0.001260241 0.0074184361 0.064653780 1.0
> LAD 0.006969928 0.0007096344 0.393556636 0.002483941
>  LAD
> lateRT  0.0069699285
> earlyRT 0.0007096344
> NAD 0.3935566356
> ciLAD   0.0024839407
> LAD 1.00
> 
> I want to use the following function to get heatmap and dendrogram
> 
> > heatmap.2(d,trace="none",margin=c(8, 10))
> 
> but it is hard to use color to make  0.001260241 and 0.0074184361 to
> be
> visualized differently.
> 
> Does anyone know how to adjust color based on these values in this
> matrix?

Have you tried to adapt the attribute "colorTable"?

You have to store the heatmap in an object (say "hm") and the use
"hm$colorTable".

See the examples here: 
https://www.rdocumentation.org/packages/gplots/versions/3.0.1.1/topics/heatmap.2

Also take a look on the documentation.

HTH,
Kimmo

__
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] Mailinglist

2019-01-06 Thread K. Elo
Hi!

Not having a data chunk prevents me from testing abit, but maybe you
should take a look on:

?table
?xtabs

to start with.

But as already suggested by other users, a small data set would be of
great help :)

HTH,
Kimmo

su, 2019-01-06 kello 13:49 -0500, Rachel Thompson kirjoitti:
> Hi Rich,
> 
> I really feel lost at this point.
> I need a code that helps me count the phone activity
> level(high/low/none),
> the screen activity (on/off) and the amount calls and SMS of each
> subject.
> 
> 1. I want to have a summary of how many times a specific subject got
> called
> (CallLogProbe)
> 2. I want to have a summary of how many times a specific subject got
> a text
> message (SMS probe)
> 3. I want to have a summary of how many times a specific subject
> - Turned their screen on - True  (ScreenProbe)
> - Or did not turn their screen on - False (ScreenProbe)
> 4.  I want to have a summary of the activity level of a specific
> subject
> - Activity level - none (ActivityProbe)
> - Activity level- low (ActivityProbe)
> - Activity level - High  (ActivityProbe)
> 
> I want to do this for all the 36 subjects(Participants).
> In the end, I have to define the percentages and cutoff points of
> what is
> considered low-medium-high, based on what the results of all the
> subjects
> are. So I am able to see if a specific subject has low social
> interaction
> etc.
> 
> I have tried a lot, with the help of youtube etc. But I feel as if I
> am
> trying a lot of things but without clearly knowing if it is the right
> step.
> I have a csv file, but I need to look into what Jeff said about the
> guides.
> So I am able to share it.
> 
> Best.
> 
> 
> On Sun, Jan 6, 2019 at 11:51 AM Rich Shepard <
> rshep...@appl-ecosys.com>
> wrote:
> 
> > On Sun, 6 Jan 2019, Rachel Thompson wrote:
> > 
> > > I am an intern from Amsterdam and I have to do an analysis in R.
> > > I spoke
> > > to my professor in Amsterdam and my supervisor's here in Boston.
> > > But they
> > > are to busy to help. I informed them from the start that I am not
> > 
> > familiar
> > > with R(Rstudio) and they told me that I would receive guidance.
> > > So since
> > > they can not help me, I decided to share my problem online. (It
> > > is a CVS
> > > file imported into R)
> > 
> > Rachel,
> > 
> >I find it interesting that you're put in such a difficult
> > position. I've
> > not followed this thread from the start so my comments might be
> > redundant
> > or
> > inappropriate.
> > 
> >If you can, describe the problem. That is, what are you being
> > asked to
> > find and what are the available data? This information helps us to
> > guide
> > you
> > to learning the mechanics for accomplishing your task with R.
> > 
> > Regards,
> > 
> > Rich
> > 
> > __
> > 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-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] data frame transformation

2019-01-06 Thread K. Elo
Hi!

Maybe this would do the trick:

--- snip ---

library(reshape2) # Use 'reshape2'
library(dplyr)# Use 'dplyr'

datatransfer<-data %>% mutate(letter2=letter) %>% 
  dcast(id+letter~letter2, value.var="weight")

--- snip ---

Or did I misunderstood something?

Best,

Kimmo

2019-01-06, 13:16 +, Andras Farkas via R-help wrote:
> Hello Everyone,
> 
> would you be able to assist with some expertise on how to get the
> following done in a way that can be applied to a data set with
> different dimensions and without all the line items here?
> 
> we have:
> 
> id<-c(1,1,1,2,2,2,2,3,3,4,4,4,4,5,5,5,5)#length of unique IDs may
> differ of course in real data set, usually in magnitude of 1
> letter<-
> c(sample(c("A","B","C","D","E"),3),sample(c("A","B","C","D","E"),4),s
> ample(c("A","B","C","D","E"),2),
>  
> sample(c("A","B","C","D","E"),4),sample(c("A","B","C","D","E"),4))#nu
> mber of unique "letters" is less than 4000 in real data set and they
> are no duplicates within same ID
> weight<-c(sample(c(1:30),3),sample(c(1:30),4),sample(c(1:30),2),
>   sample(c(1:30),4),sample(c(1:30),4))#number of unique
> weights is below 50 in real data set and they are no duplicates
> within same ID
> 
> 
> data<-data.frame(id=id,letter=letter,weight=weight)
> 
> #goal is to get the following transformation where a column is added
> for each unique letter and the weight is pulled into the column if
> the letter exist within the ID, otherwise NA
> #so we would get datatransform like below but without the many steps
> described here
> 
> datatransfer<-data.frame(data,apply(data[2],2,function(x)
> ifelse(x=="A",data$weight,NA)))
> datatransfer<-
> data.frame(datatransfer,apply(datatransfer[2],2,function(x)
> ifelse(x=="B",data$weight,NA)))
> datatransfer<-
> data.frame(datatransfer,apply(datatransfer[2],2,function(x)
> ifelse(x=="C",data$weight,NA)))
> datatransfer<-
> data.frame(datatransfer,apply(datatransfer[2],2,function(x)
> ifelse(x=="D",data$weight,NA)))
> datatransfer<-
> data.frame(datatransfer,apply(datatransfer[2],2,function(x)
> ifelse(x=="E",data$weight,NA)))
> 
> colnames(datatransfer)<-c("id","weight","letter","A","B","C","D","E")
> much appreciate the help,
> 
> thanks
> 
> Andras 
> 
> __
> 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] Importing JSON Files

2018-11-05 Thread K. Elo
Hi!

Have you tried to use 'fromJSON' with the parameter 'simplifyDataFrame'
set to TRUE?

See: 
https://cran.r-project.org/web/packages/jsonlite/vignettes/json-aaquickstart.html
 -> Section "Data Frames" explains how this affects the data frame
structure. IMHO this should solve your problem...

Best,
Kimmo

2018-11-05 19:00 +, JEFFERY REICHMAN wrote:
> r-help Forum
> 
> Struggling with importing and creating a data.fram from a JSON
> file.  I used the jsonlite package (fromJSON function) and I can see
> the resulting table but one of the attributes is a list (of lists) So
> I have something that looks like .
> 
> favorites (attribute)
> list(favoriteValue = c("12345", 23456"), resourceType = c("abc",
> "def"), classification = c("xxx","yyy"))
> 
> So when I attempt to create a data.frame R errors out.  I'm assuming
> it is because of the list(s).  Don't know what to do with it (the
> list).  I need the "favoriteValue (s)."
> 
> Ultimate I want to run the arules package
> 
> Jeff Reichman
> 
> __
> 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] Saving objects in RData file in different name

2018-07-28 Thread K. Elo
Hi!

Maybe not the most elegant solution, but a workaround is to have a
function:

> save2<-function(y, ...) { save(y,...)}
> save2(x1,x2,file="test.RData")

The point is to include the variables to be "renamed" as parameters (in
my example: y). The function will use the parameter variable names when
saving the file.

HTH,
Kimmo

2018-07-28, 17:04 +0530, Christofer Bogaso wrote:
> Hi,
> 
> Let say I have 2 objects as below
> 
> x1 = 1:3
> x2 = 5:4
> 
> Now I want to save both x1 and x2 in some RData file, however x1 will
> be
> saved with a different name e.g. y
> 
> I tried below
> 
> save(y = x1, x2, file = "file.RData")
> 
> However still they are saved in their original names i.e. x1 and x2,
> not y
> and y2.
> 
> Is there any possibility that I can achieve above without explicitly
> copying y = x1 before y is passed to save()
> 
> Thanks for any feedback.
> 
>   [[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-gui
> de.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] Split a data.frame

2018-05-19 Thread K. Elo
Hi!

How about this:

--- snip --

for (i in 1:(length(split_str)-1)) {
assign(paste("DF",i,sep=""),DF[
c((which(DF$name==split_str[i])+1):(which(DF$name==split_str[i+1])-1)), 
])
}

--- snip ---

'assign' creates for each subset a new data.frame DFn, where n ist a
count (1,2,...).

But note: if your DF has duplicates in 'name' (e.g. two rows with 'a'
in 'DF$name'), my solution will use the first occurrence only (and this
for both start and for end).

HTH,
Kimmo

2018-05-19 kello 16:37 +0530, Christofer Bogaso wrote:
> Hi,
> 
> I am struggling to split a data.frame as will below scheme :
> 
> DF = data.frame(name = c('a', 'v', 'c'), val = 0); DF
> 
> split_str = c('a', 'c')
> 
> Now, for each element in split_str, R should find which row of DF
> contains
> that element, and return DF with all rows starting from next row of
> the
> corresponding element and ending with the preceding value of the next
> element.
> 
> So in my case, I should see 2 data.frames
> 
> 1st data-frame with name = 'v' (i.e. 2nd row of DF)
> 
> 2nd data.frame with number_of_rows as 0 (as there is no row left
> after 'c')
> 
> Similarly if split_str = c('v'') then, my 2 data.frames will be
> 
> 1st data.frame with name = 'a'
> 2nd data.frame with name = 'c'
> 
> Any idea how to efficiently implement above scheme would be highly
> appreciated. I tried with split() function, however, it is not giving
> the
> right answer.
> 
> Thanks,
> 
> __
> 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-gui
> de.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] help with json data from the web into data frame in R

2018-05-12 Thread K. Elo
Hi!

Seems to be an encoding problem. This worked for me (have not full-
checked the output, though):

fromJSON(encodeString(zWebObj))

HTH,
Kimmo

2018-05-08 12:49 -0700, David Winsemius wrote:
> > 
> > On May 8, 2018, at 10:08 AM, Evans, Richard K. (GRC-H000)  > k.ev...@nasa.gov> wrote:
> > 
> > Hi David,  .. I think I've got it :-) 
> > Please let me know if you see anything glaringly wrong with this:
> > 
> > library(RCurl)
> > zWebObj <- postForm("https://www.semantic-mediawiki.org/w/api.php;,
> >   "action" = "ask",
> >   "query" = "[[Category:City]]|?Capital%20of|?Has%20area",
> >   "format" = "json"
> >   .opts = list(ssl.verifypeer = FALSE)
> > )
> > 
> The R interpreter tells me there's a missing comma after the line: 
> 
> "format" = "json"
> 
> Fixing that syntactic error I get:
> 
> str(zWebObj)
> # ---bein console output
>  atomic [1:1]
> {"query":{"printrequests":[{"label":"","key":"","redi":"","typeid":"_
> wpg","mode":2}],"results":{"File:2166320938 | __truncated__
>  - attr(*, "Content-Type")= Named chr [1:2] "application/json" "utf-
> 8"
>   ..- attr(*, "names")= chr [1:2] "" "charset"
> #--- end console output-
> js1 <-fromJSON(zWebObj)
> #
> Error: lexical error: inside a string, '\' occurs before a character
> which it may not.
>   title":""}},"serializer":"SMW\Serializers\QueryResultSerial
> i
>  (right here) --^
> 
> 
> I'm not really a JSON expert, so am not equipped to offer debugging
> assistance there.
> 
> -- 
> David.
> 
> 
> > 
> > Thank you!
> > -Rich
> > 
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> > Evans, Richard K. (GRC-H000)
> > Sent: Tuesday, May 08, 2018 12:51 PM
> > To: David Winsemius
> > Cc: r-help@r-project.org
> > Subject: Re: [R] help with json data from the web into data frame
> > in R
> > 
> > [non-tabular json data] -- ok.. so I think I need to figure out how
> > to make it tabular. Thanks!
> > 
> > [curl] -- I was hoping there was a cleaner way to do it.. using R
> > to evoke cURL to get the data as text and then passing it into
> > getJSON seems to be what I need to do.
> > 
> > Do you by chance have an simple example of using RCurl to get a
> > response ignoring cert errors?
> > 
> > ty
> > -Rich
> > 
> > -Original Message-
> > From: David Winsemius [mailto:dwinsem...@comcast.net] 
> > Sent: Tuesday, May 08, 2018 12:25 PM
> > To: Evans, Richard K. (GRC-H000)
> > Cc: r-help@r-project.org
> > Subject: Re: [R] help with json data from the web into data frame
> > in R
> > 
> > 
> > > 
> > > On May 8, 2018, at 9:03 AM, Evans, Richard K. (GRC-H000)  > > .k.ev...@nasa.gov> wrote:
> > > 
> > > That said, I have two issues to ask for help with:
> > > 
> > > 1) how to ignore cert errors with a fromJSON call
> > If you can do it with curl, then why aren't you doing one of a) a
> > system call, b) installing and loading RCurl, c) installing and
> > loading curl (the R package with that name)?
> > 
> > > 
> > > 
> > > And 
> > > 
> > > 2) why the json data from the example link doesn't convert to a
> > > data frame.
> > That was already answered in my earlier response. It's not a
> > tabular result, so it doesn't "fit" into a tabular structure.
> >

__
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] Hacked

2018-04-17 Thread K. Elo
Hi!

Not just an gmail issue. After my last reply I have gotten tons of
spams from "Samantha Smith". Keep hitting my "rank as spam"-button in
the hope that my MUA could learn :)

Best,
Kimmo

ti, 2018-04-17 kello 19:34 +, Ding, Yuan Chun kirjoitti:
> No, I do not use gmail, still got dirty spam email twice. 
> 
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> Fowler, Mark
> Sent: Tuesday, April 17, 2018 12:32 PM
> To: Luis Puerto; Peter Langfelder
> Cc: R-Help ML R-Project; Neotropical bat risk assessments
> Subject: Re: [R] Hacked
> 
> [Attention: This email came from an external source. Do not open
> attachments or click on links from unknown senders or unexpected
> emails.]
> 
> 
> 
> 
> 
> Just an observation. I have not seen the spam you are discussing.
> Possibly it is specific to gmail addresses?
> 
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luis
> Puerto
> Sent: April 17, 2018 4:11 PM
> To: Peter Langfelder
> Cc: R-Help ML R-Project; Neotropical bat risk assessments
> Subject: Re: [R] Hacked
> 
> Hi! 
> 
> This happened to me also! I just got a spam email just after posting
> and then in following days I got obnoxious spam emails in my spam
> filter. As the others, I think that there is some kind of bot
> subscribed to the list, but also perhaps a spider or crawler
> monitoring the R-Help archive and getting email addresses there.
> Nabble is a possibility too. 
> 
> > 
> > On 17 Apr 2018, at 21:50, Peter Langfelder  > com> wrote:
> > 
> > I got some spam emails after my last post to the list, and the
> > emails 
> > did not seem to go through r-help. The spammers may be subscribed
> > to 
> > the r-help, or they get the poster emails from some of the web
> > copies 
> > of this list (nabble or similar).
> > 
> > Peter
> > 
> > On Tue, Apr 17, 2018 at 11:37 AM, Ulrik Stervbo  > l.com> wrote:
> > > 
> > > I asked the moderators about it. This is the reply
> > > 
> > > "Other moderators have looked into this a bit and may be able to
> > > shed 
> > > more light on it. This is a "new" tactic where the spammers
> > > appear to 
> > > reply to the r-help post. They are not, however, going through
> > > the r-help server.
> > > 
> > > It also seems that this does not happen to everyone.
> > > 
> > > I am not sure how you can automatically block the spammers.
> > > 
> > > Sorry I cannot be of more help."
> > > 
> > > --Ulrik
> > > 
> > > Jeff Newmiller  schrieb am Di., 17.
> > > Apr. 
> > > 2018,
> > > 14:59:
> > > 
> > > > 
> > > > Likely a spammer has joined the mailing list and is auto-
> > > > replying to 
> > > > posts made to the list. Unlikely that the list itself has been 
> > > > "hacked". Agree that it is obnoxious.
> > > > 
> > > > On April 17, 2018 5:01:10 AM PDT, Neotropical bat risk
> > > > assessments < 
> > > > neotropical.b...@gmail.com> wrote:
> > > > > 
> > > > > Hi all,
> > > > > 
> > > > > Site has been hacked?
> > > > > Bad SPAM arriving
> > > > > 
> > > > > __
> > > > > 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.
> > > > --
> > > > Sent from my phone. Please excuse my brevity.
> > > > 
> > > > __
> > > > 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-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 htt
> ps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-gui
> de.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

Re: [R] how to write a loop to repetitive jobs

2018-04-17 Thread K. Elo
Hi!

An alternative with 'assign':

for ( i in 71:75) {
  setwd(paste("C:/Awork/geneAssociation/removed8samples/neuhausen", i,
sep=""))
  temp.df<-read.csv("seg.pr3.csv", head=T)
  temp.df$id<-paste0("sn",i,sep="")
  assign(paste0("seg",i,sep=""),temp.df)
}
rm(temp.df,i)    # Clean up

HTH,
Kimmo


2018-04-17 kello 08:15 +0200, Albrecht Kauffmann wrote:
> Hello Ding,
> 
> try this:
> 
> seg <- list()
> for ( d in 71:75) {
>   s <- paste0("seg",d)
>   sn <- paste0("sn",d)
>   Dir<-paste("C:/Awork/geneAssociation/removed8samples/neuhausen", i,
> sep="")
>   setwd(Dir)
>   seg[[s]] <- read.csv("seg.pr3.csv", head=T)
>   seg[[s]]$id <- sn
> }
> 
> Greetings,
> Albrecht
>

__
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] help matching rows of a data frame

2017-09-18 Thread K. Elo
Hi!
2017-09-18 07:13 -0500, Therneau, Terry M., Ph.D. wrote:
> This question likely has a 1 line answer, I'm just not seeing
> it.  (2, 3, or 10 lines is 
> fine too.)
> 
> For a vector I can do group  <- match(x, unqiue(x)) to get a vector
> that labels each 
> element of x.

Actually, you get a vector of indices matching 'unique(x)', not a
labelled vector.

> x<-c("A","B","C","A","C","D")
> group<-match(x, unique(x))
> group
[1] 1 2 3 1 3 4

> What is an equivalent if x is a data frame?

So you will generate an index where duplicated rows have the row index
of the first occurrence, right? This could work:

> x<-data.frame("X0"=c("A","B","C","C","D","A"), "X1"=c(1,2,1,1,3,1))
> group<-rownames(x)
> for (i in 1:(nrow(x)-1)) { 
     for (j in (i+1):nrow(x)) { 
        if (sum(as.numeric(x[i,]==x[j,]))==ncol(x)) { 
           group[j]<-group[i] }
     }
   }
>  group
[1] "1" "2" "3" "3" "5" "1"

HTH,
Kimmo

__
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] R studio Problem

2016-12-14 Thread K. Elo

Hi!

Maybe this helps:

http://r.789695.n4.nabble.com/Error-in-normalizePath-path-with-McAfee-td2532324.html

Best,
Kimmo

15.12.2016, 08:18, Amelia Marsh via R-help wrote:

Hi

I had installed R studio Desktop 1.0.44. However whenever I wanted to write any 
command, before I could complete, I was getting following error

Error in normalizePath(dir, winslash = "/", mustWork = TRUE) :
unused argument(s) (winslash = "/", mustWork = TRUE)


I had uninstalled RStudio and again downloaded it and reinstalled. But still I 
am getting error like as mentioned below -



a = 40



b = 45

Error in normalizePath(dir, winslash = "/", mustWork = TRUE) :
unused argument(s) (winslash = "/", mustWork = TRUE)

c = 120

Error in normalizePath(dir, winslash = "/", mustWork = TRUE) :
unused argument(s) (winslash = "/", mustWork = TRUE)
Error in normalizePath(dir, winslash = "/", mustWork = TRUE) :
unused argument(s) (winslash = "/", mustWork = TRUE)
Error in normalizePath(dir, winslash = "/", mustWork = TRUE) :
unused argument(s) (winslash = "/", mustWork = TRUE)
Error in normalizePath(dir, winslash = "/", mustWork = TRUE) :
unused argument(s) (winslash = "/", mustWork = TRUE)
Error in normalizePath(dir, winslash = "/", mustWork = TRUE) :
unused argument(s) (winslash = "/", mustWork = TRUE)


I had assigned value 40 to a, value 45 to b, but when I tried to assign value 
120 to c, before I could complete, it started throwing above messages. I tried 
rnorm etc, however the error keeps on reappearing.


Can someone guide me.

Regards

Amelais

__
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] JSON to Dataframe

2016-10-18 Thread K. Elo

Hi!

18.10.2016, 14:38, Abhinaba Roy wrote:

Hi R helpers,

I have json inputs from an app which I want to convert to dataframes. Below
are the two inputs. Can someone help me in converting these to dataframes


[...]

IMHO, the best way is to use the package 'jsonlite', see:

* https://cran.r-project.org/web/packages/jsonlite/index.html

A good documentation comes with the package, but the links listed on the 
CRAN site provide useful information, too.


HTH,
Kimmo

__
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] Maybe OT: Forking in R scripts?

2016-10-13 Thread K. Elo

Dear all,

I am currently working a research project on social media interaction. 
As a part of this project, mostly for teaching purposes, I should 
develop a R-based approach for real-time visualisation of streamed data 
(from Twitter).


My idea is simple (and working :) ): A Python-script stream Twitter for 
selected keywords/hashtags/users and redirects the output as JSON in a 
text file. My R-script reads the new entries from this text file every 
5-10 minutes, process the input and updates network and other graphical 
presentations.


Thus far everything is working fine. However, I would like to have the 
possibility to work with my data when my script is sleeping. I just 
wonder whether a simple 'mcparallel({ Sys.sleep(300); TRUE})' (from 
'parallel') would solve my problem? Or is there something I have to take 
into account when using 'parallel'?


My R environment runs on Linux, so forking should work...

Best regrads and thanks in advance,
Kimmo

--
Åbo Akademi University, Finland
Dep. for German studies

__
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] Hierarchical Clustering in R

2016-08-24 Thread K. Elo

Hi,

what is the exact problem? I tried you code and it works fine...

Best,
Kimmo

24.08.2016, 10:07, Serpil ŞEN wrote:

Dear Authorized Sir / Madam,

I need your help on clustering with R.

I have symmetric distance matrix which i created usign ClustalOmega program.

and used this R codes for clustering purpose.

*data=read.table("my_distance_matrix", header=FALSE)[-1]*
*attach(data)*
*head(data)*
*d=as.dist(data);*

*hc.complete=hclust(d,method="complete")*

*cutree(hc.complete, k=6)*
*groups<- cutree(hc.complete, k=6)*
*x<-cbind(groups)*
*x*
*x1<- subset(x,groups==1)*
*write.table(x, "results.txt", sep="\t")*
*plot(hc.complete)*


I am wondering am i doing wrong usign this code
?(*data=read.table("my_distance_matrix
or data file ???", header=FALSE)[-1]*)
Is this line requires normal data values?  In this line what kind of file
have to use? Normal data file or distance matrix?

*d=as.dist(data);  *With this line am i calculating twice distance
matrix?

Thanks 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.

Re: [R] Y in Kohonen xyf function

2016-06-22 Thread K. Elo

Hi!

22.06.2016, 22:00, chalabi.el...@yahoo.de wrote:

Dear Kimmo,
I already used df$speed[training] in df.xyf but I get this error:
   Error in xyf(Xtraining,factor(df$speed[training]),grid=somgrid(5, :
   NA/NaN/Inf in foreign function call (arg 1)


Please check for zeros (0) and NAs in df$speed or Xtraining. They could 
be a problem here...


HTH,
Kimmo

__
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] Y in Kohonen xyf function

2016-06-22 Thread K. Elo

Hi again!

21.06.2016, 21:33, chalabi.el...@yahoo.de wrote:

Hi Kimmo, Thanks for your reply. I think now my problem is that I
don't understand what does factor(df.classes[training]) do?


Sorry, my mistake, should habe been 'df$speed'. Please try the following:

--- snip ---

set.seed(7) training <- sample(nrow(df), 120)
Xtraining<- scale(df[training,])
Xtest <- scale(df[-training,], center = attr(Xtraining, 
"scaled:center"), scale = attr(Xtraining,

"scaled:scale"))
xyf.df <- xyf(Xtraining, factor(df$speed[training]), grid =
somgrid(5, 5, "hexagonal"))

--- snip ---

HTH,
Kimmo

__
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] Y in Kohonen xyf function

2016-06-17 Thread K. Elo

Hi again!

According to '?xyf', the function is expecting following parameters:

(1) data = a matrix, with each row representing an object.

So, please ensure that your data is a matrix

(2) Y = property that is to be modelled. In case of classification, Y is 
a matrix of zeros, with exactly one '1' in each row indicating the 
class. For prediction of continuous properties, Y is a vector. A 
combination is possible, too, but one then should take care of 
appropriate scaling.


Once again, no data frame here, but a scaled vector or a matrix.

Your could try following steps (I assume 'df' to be you data frame):

--- snip ---
set.seed(7)
training <- sample(nrow(df), 120)
Xtraining <- scale(df[training,])
Xtest <- scale(df[-training,],
   center = attr(Xtraining, "scaled:center"),
   scale = attr(Xtraining, "scaled:scale"))

xyf.df <- xyf(Xtraining,
  factor(df.classes[training]),
  grid = somgrid(5, 5, "hexagonal"))

--- snip ---

Let us know - with output, please - what happens. The point is, if this 
works, then you could try in experimenting the parameter 
'factor(df.classes[training]'. It seems to, that also here you need a 
matrix or a list as a base, not a data frame.


This might also be of interest for your: 
https://www.jstatsoft.org/article/view/v021i05/v21i05.pdf


HTH,
Kimmo

16.06.2016, 17:30, chalabi.el...@yahoo.de wrote:

Hi Kimmo,

Thanks for your reply, Here is a part of my df:


 'data.frame':  562 obs. of 128 variables
 $ TE :int 37 37 35 34 37 37 35 33 32 ...
 $ TR :int 11 11 8 13 11 8 15 12 8 .
 $ BW :int 150 191 128 145 200 191 
 $speed   :int 4 4 3 3 2 1 4 1 2 3 ..
and I want to cluster my data based on speed, to see the coming costumer's 
protocols fall into which speed group and I think I need to bring this speed 
column in Y element of xyf


On Thursday, June 16, 2016 2:29 PM, K. Elo <mailli...@pp.inet.fi> wrote:
Hi!

Some sample data could help us to help you...

But have you read '?xyf' in order to ensure that your 'Y' is what 'xyf'
expects it to be?

What kind of error messages do you get?

Regards,
Kimmo

16.06.2016, 15:13, ch.elahe via R-help wrote:

Is there any answer?


Hi all, I have a df and I want to use supervised Self Organizing Map
to do classification. I should use Kohonen library and xyf function
from it. As you know the xyf function looks like this and I have
problem defining my Y:

xyf(data,Y,grid=somgrid(),rlen=100,alpha=c(0.05,0.01)) I want to do
classification based on a column which shows the speed that a
protocols is run, and this column is the following:

$speed   :num 4 4 3 3 3 1 1 1 2 1 4 4 3 numbers from 1 to 4 show the
speed from very fast to very slow protocols. so the property I want
to be modeled is df$speed, but I don't know how should I bring it in
xyf function. Does anyone know how to do that? I also added my train
set ans test set:

dt=sort(sample(nrow(df),nrow(df)*.7)) train=df[dt,]
Xtraining=scale(trian) Xtest=scale(-trian)
center=attr(Xtrianing,"scaled:center")
scale=attr(Xtraining,"scaled:scale")
xyf(Xtraining,,grid=somgrid(10,10,"hexagonal"))


Thanks for any Help, 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.




__ 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-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] Y in Kohonen xyf function

2016-06-16 Thread K. Elo

Hi!

Some sample data could help us to help you...

But have you read '?xyf' in order to ensure that your 'Y' is what 'xyf' 
expects it to be?


What kind of error messages do you get?

Regards,
Kimmo

16.06.2016, 15:13, ch.elahe via R-help wrote:

Is there any answer?


Hi all, I have a df and I want to use supervised Self Organizing Map
to do classification. I should use Kohonen library and xyf function
from it. As you know the xyf function looks like this and I have
problem defining my Y:

xyf(data,Y,grid=somgrid(),rlen=100,alpha=c(0.05,0.01)) I want to do
classification based on a column which shows the speed that a
protocols is run, and this column is the following:

$speed   :num 4 4 3 3 3 1 1 1 2 1 4 4 3 numbers from 1 to 4 show the
speed from very fast to very slow protocols. so the property I want
to be modeled is df$speed, but I don't know how should I bring it in
xyf function. Does anyone know how to do that? I also added my train
set ans test set:

dt=sort(sample(nrow(df),nrow(df)*.7)) train=df[dt,]
Xtraining=scale(trian) Xtest=scale(-trian)
center=attr(Xtrianing,"scaled:center")
scale=attr(Xtraining,"scaled:scale")
xyf(Xtraining,,grid=somgrid(10,10,"hexagonal"))


Thanks for any Help, 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.

__ 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] TwitteR - Number of tweets from multiple locations

2016-06-01 Thread K. Elo

Hi Juho!

01.06.2016, 14:40, Juho Kiuru wrote:

Hi all, I am new to R and TwitteR and would love to get some advice from
you.

I managed to get list of tweets containing word 'innovation' tweeted in
Helsinki with following script:

searchTwitter('innovation', n=1, geocode='60.1920,24.9458,30mi',
since="2016-01-01", until="2016-05-31")

However, I was wondering is it possible to involve multiple locations to
script, so that the result would be number of tweets in each location.

For example, something like this:
Location Tweets
Helsinki 300
Berlin 400
Barcelona 500


Have your read the documentation ('?searchTwitter'). The argument 
'geocode' cannot be a list, only a single value.


A possible workaround could be to filter tweets based on geocode after 
you have received these. However, since your search pharse is rather ge 
general, you would receive a lot of "noise" as well.


One possibility would be to write a loop with three 'searchTwitter' 
calls with different geocodes. Here you could speed up the data 
collection by setting 'n' to e.g. 100 or 500.


You should, however, consider the fact that geocodes are often supressed 
by the user, so that you would most certainly get only a limited amount 
of tweets.



Another problem I faced is in setting the time span I would like to have
the count of tweets from. I tried to set the time span from the beginning
of this year to end of May, but it seems like I get only tweets from the
last week of May.


If I remember correctly this is not related to twitteR, but to the 
Twitter API itself. The API limits your search results to contain tweets 
from the last 7 days only.


HTH,
Kimmo

--
Kimmo Elo
Åbo Akademi University, Finland / German studies
University of Turku, Finland / DIGIN - Digital Humanities Network

__
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] Scale y-labels based on a value with 'lattice'

2016-05-29 Thread K. Elo

Hi!

Many thanks to Duncan and Jim for their quick replies.

27.05.2016, 01:08, Jim Lemon wrote:

Hi Kimmo,
par(mar=c(5,7,4,2))
dotchart(kedf$x)
mtext(kedf$Group.2,side=2,at=1:6,line=0.5,
 las=2,cex=log(abs(kedf$Freq))+1)

Jim


This 'dotchart' solution worked fine and I got what I wanted :) However, 
I still wonder why the same idea does not work with lattice (e.g. using 
'scales=list(y=list(cex=log(abs(kedf$Freq))+1))'


27.05.2016, 08:51, Duncan Mackay wrote:

Hi

If you want to change the cex of the labels see

library(lattice)
 ?yscale.components.default


Seem a bit more complex, but I'll give it a try.


Possibly an easier way is to size the symbols

I will use Jims data.frame to plot with lattice
dotplot(Group.2 ~ x, data = kedf,
 scales = list(y = list(labels = kedf[,"Group2"], cex = = 
kedf[,"Freq"])))
[...}
Regards

Duncan


This is also a nice idea to scale the dots. Thanks for pointing this out.

Best,
Kimmo

__
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] Scale y-labels based on a value with 'lattice'

2016-05-26 Thread K. Elo

Dear R-helpers!

I have a data frame storing data for word co-occurrences, average 
distances and co-occurence frequency:


  Group.1Group.2 x Freq
1 deutschland  achtziger  2.001
2 deutschlandalt  1.254
3 deutschland anfang -2.001
4 deutschlandansehen  1.002
5 deutschland arbeit  0.502
6 deutschland arbeitslos -2.001

Now I want to plot a lattice 'dotplot' with the formula 'Group.2~x'. 
This works fine.


However, I would like to scale the y-label (based on 'Group.2' according 
the 'Freq' value using a log-scaled value (log(Freq+.5)). In other 
words: the higher the 'Freq' value of a term, the bigger its label 
should be printed in my dotplot.


The problem is that I cannot figure out how to tell lattice to scale 
each y-label with according 'Freq' value. I am quite sure I should build 
a function for scales=list(y=...), but I don't know how to it.


Many thanks in advance for your help!

Best,
Kimmo Elo

--
Åbo Akademi University / German studies
Turku, Finland

__
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] JSONlite import problem

2015-10-25 Thread K. Elo

Hi,

thanks to Duncan and Jeroen to quick replies. I was actually my thinking 
error :) I suppoed 'fromJSON' to cope with a multi-line file or a list, 
but this seems not to be the case. So I first read the file with 
'readLines' into a list and processed all items with 'fromJSON' within a 
for-loop. This worked.


Best,
Kimmo

25.10.2015, 01:27, Jeroen Ooms wrote:

On Sat, Oct 24, 2015 at 1:35 PM, Duncan Murdoch
 wrote:



However, editing the file with a text editor to create "proper" EOF
doesn't help.


The problem is that you have valid-looking JSON objects on each odd
numbered line, separated by single blank lines.  The parser expects an
EOF at the end of the first object, but instead it found a blank line
and another object.



Actually this is a common json streaming format called ndjson a.k.a.
jsonlines. Usually you can stream-import the data directly in jsonlite
using the stream_in function. See ?stream_in for examples.

However in this case there are white lines in between the json lines
which makes it a bit more tricky. I will add a feature to skip over
those lines.



__
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] JSONlite import problem

2015-10-23 Thread K. Elo

Hi!

You can download the example file with this link:
https://www.dropbox.com/s/tlf1gkym6d83log/example.json?dl=0

BTW, I have used a JSON validator and the problem seems to related to 
wrong/missing EOF.


--- snip ---
Error: Parse error on line 1:
...:"1436705823768"} {"created_at":"Sun J
-^
Expecting 'EOF', '}', ',', ']', got '{'
--- snip ---

However, editing the file with a text editor to create "proper" EOF 
doesn't help.


-Kimmo-

23.10.2015, 22:52, Duncan Murdoch wrote:

It looks like it's the same sort of problem as in that stackoverflow
posting:  what's in your file is not valid Javascript, so it's not valid
JSON.  It's probably multiple JSON objects without proper separators;
you need to do the separating yourself.

BTW, your attachment failed; only some file types are allowed.  You
should probably put the file online somewhere and post the URL.

Duncan Murdoch


__
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] JSONlite import problem

2015-10-23 Thread K. Elo

Hi!

I have collected 500.000+ tweets with a Python script using 'tweepy', 
which stored the data in JSON format. I would like to use R for data 
analysis, but have encountered problems when trying to import the data 
file with 'jsonlite'.


Here what I have tried:

> data.df<-fromJSON("example.json")
Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) :
  parse error: trailing garbage
  stamp_ms":"1436705823768"}   {"created_at":"Sun Jul 12 12:57
 (right here) --^

The import fails already on the first line :( A sample file causing this 
error is attached.


I have tried several solutions, e.g. this:
http://stackoverflow.com/questions/26519455/error-parsing-json-file-with-the-jsonlite-package

but it does not work and results in the same error.

Could anyone help me to understand what is causing the error and how to 
solve the issue? Thanks in advance.


Kind regards,
Kimmo Elo

--
University of Turku, Finland
Dep. of political science and contemporary history
__
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] Choosing columns by number

2015-08-25 Thread K. Elo



Hi!

25.08.2015, 18:17, Sam Albers wrote:

Hi all,

This is a process question. How do folks efficiently identify column
numbers in a dataframe without manually counting them. For example, if I
want to choose columns from the iris dataframe I know of two options. I can
do this:


str(iris)'data.frame':  150 obs. of  5 variables:

  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
  $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1
1 1 1 1 1 1 ...

or this:


names(iris)[1] Sepal.Length Sepal.Width  Petal.Length Petal.Width  
Species


Neither option explicitly identifies the column number so that I can
do something like this:

iris[,c(2,4)]

I feel like there must be a better way to do this so I wanted to ask
the collective wisdom here what people do to accomplish this.
Obviously this is a trivial example, but the issue really becomes
problematic when you have a large dataframe.


Maybe with 'which'?

 which(colnames(iris)==Sepal.Length)
[1] 1

Or did I somehow misunderstood what you are looking for?

HTH,
Kimmo

__
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] reading as date

2015-06-10 Thread K. Elo

Hi!

10.06.2015, 13:20, khatri wrote:

My date column is in following format : %m/%d H:M:S
There is not mention of year in the data.So how can I read this using
strptime function.
I have tried strptime(dates,%m/%d H:M:S) but this is returning NA.
Thanks


How about:

strptime(dates,%m/%d %H:%M:%S)

Some data could also be helpful for testing...

HTH,
Kimmo

__
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] remove duplicated row according to NA condition

2014-05-28 Thread K. Elo
Hi!

How about trying this:

data[ data$col1!=data$col2  !is.na(data$col3), ]

  col1 col2  col3
2a1 ST001
3b2 ST002

HTH, Kimmo


28.05.2014 15:35, jeff6868 wrote:
 Hi everybody,
 
 I have a little problem in my R-code which seems be easy to solve, but I
 wasn't able to find the solution by myself for the moment.
 
 Here's an example of the form of my data:
 
 data -
 data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA))
 
 I would like to remove duplicated data based on the first two columns
 (col1,col2), but in both cases here, I would like to remove the duplicated
 row which is equal to NA in col3.
 
 Here's the data.frame I would like to obtain:
 
 data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002))
 
 I've been trying to mix duplicated() with is.na() but it doesn't work yet.
 
 Can someone tell me the best and easiest way to do this?
 
 Thanks a lot!
 
 
 
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.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] How to test if there is a subvector in a longer vector

2012-09-28 Thread K. Elo

Hi!

28.09.2012 08:41, Atte Tenkanen wrote:

Sorry. I should have mentioned that the order of the components is important.

So c(1,4,6) is accepted as a subvector of c(2,1,1,4,6,3), but not of 
c(2,1,1,6,4,3).

How to test this?


How about this:

--- code ---

g1- c(2,1,1,4,6,3)
g2- c(2,1,1,6,4,3)
t1- c(1,4,6)
t2-c(9,8)

!is.na(sum(match(t1,g1)))
[1] TRUE
!is.na(sum(match(t1,g2)))
[1] TRUE
!is.na(sum(match(t2,g1)))
[1] FALSE

--- code ---

Kind regads,
Kimmo

__
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] Simple Question

2012-09-28 Thread K. Elo

Hi!

28.09.2012 09:13, Bhupendrasinh Thakre wrote:

Statement I tried :

b - unclass(Sys.time())
b = 1348812597
c_b - rnorm(1,2,1)


Do you mean this:

--- code ---

 df-data.frame(x=0,y=0)
 colnames(df)
[1] x y
 colnames(df)[2]-paste(b,unclass(Sys.time()),sep=_)
 colnames(df)
[1] x  b_1348813791.55393

--- code ---

HTH,
Kimmo

__
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] Cannot install the 'igraph' package

2012-08-03 Thread K. Elo

Hi!

On Thu, 2 Aug 2012, Prof Brian Ripley wrote:
You may bave a micro-packaged distribution (some form of SuSE as I recall): 
is there a separate R-devel RPM?  (Fedora had one an one time.)


Thanks, this made the trick. After having R-base-devel installed I 
succeeded in intalling the 'igraph' package.


Kind regards,
Kimmo

__
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] Cannot install the 'igraph' package

2012-08-02 Thread K. Elo

Hi!

I want to use R for network analysis and have tried to install the 
'igraph' package. Unfortunately, the installation is aborted by an error:


--snip--
gcc -std=gnu99 -I/usr/lib64/R/include -DNDEBUG  -I/usr/local/include 
-DUSING_R -I. -Ics -Iglpk -Iglpk/amd -Iglpk/colamd -I/usr/local/include 
-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -g -DNDEBUG 
-DPACKAGE_VERSION=\0.6\ -DINTERNAL_ARPACK -DIGRAPH_THREAD_LOCAL=/**/ 
-fpic  -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -g  -c rinterface.c -o 
rinterface.o

rinterface.c:30:15: fatal error: R.h: File or directory does not exist!
compilation terminated.
make: *** [rinterface.o] Error 1
ERROR: compilation failed for package ‘igraph’
* removing ‘/usr/lib64/R/library/igraph’

The downloaded source packages are in
‘/tmp/RtmpSFsTPv/downloaded_packages’
Updating HTML index of packages in '.Library'
Making packages.html  ... done
Warning message:
In install.packages(igraph) :
  installation of package ‘igraph’ had non-zero exit status

--snip--

And yes, I have asked Mr. Google, but none of the suggested solutions did 
work. I have tried to install previous versions, no success :(


Any ideas how to install 'igraph'?

I use R 2.15.1 on openSuSE 12.1 (64-bit).

Thanks in advance,
Kimmo__
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] Cannot install the 'igraph' package

2012-08-02 Thread K. Elo

Hi!

On Thu, 2 Aug 2012, Uwe Ligges wrote:
R.h should be part if your R installation, given the output above 
probably in /usr/lib64/R/include ?


But there is no such file R.h in my system???

~$ locate \/R.h
~$

Or with 'find':

# find / -name R.h
#

Any ideas?

Kind regards,
Kimmo

__
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 add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-07 Thread K. Elo

Hi!

I recently posted a similar question (entitled Adding mean line to a 
lattice density plot). Have not got any usable solution forcing my to 
fall back to the use of the normal 'plot' function. The problem was the 
same as yours: using panel.abline simply did not work, the position of 
the mean line was incorrect. I have posted a workaround (based on plot), 
please see my earlier posting.


HTH,
Kimmo

07.06.2012 15:37, maxbre wrote:

...and what if I need to plot another vertical line for showing also the
means for each panel?
by simply adding another call to panel.abline () seems not producing a
correct result for each panel

# medians and means for each panel:
dotplot(variety ~ yield | site, data = barley,
scales=list(x=list(log=TRUE)),
layout = c(1,6),
panel = function(x,y,...) {
panel.dotplot(x,y,...)
median.values- median(x)
panel.abline(v=median.values, col.line=red)
mean.values- mean(x)
panel.abline(v=mean.values, col.line=red)
})

In the dataset I'm currently working on (which is not the above mentioned
example) I've got a wrong plottting of the means for each panel, what I'm
missing?

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.


Re: [R] grouping

2012-04-03 Thread K. Elo

Hi!

Maybe not the most elegant solution, but works:

for(i in seq(1,length(data)-(length(data) %% 3), 3)) { 
ifelse((length(data)-i)3, { print(sort(data)[ c(i:(i+2)) ]); 
print(mean(sort(data)[ c(i:(i+2)) ])) }, { print(sort(data)[ 
c(i:length(data)) ]); print(mean(sort(data)[ c(i:length(data)) ])) } ) }


Produces:

[1] 36 45 46
[1] 42.3
[1]  66  78 125
[1] 89.7
[1] 193 209 242 297
[1] 235.25

HTH,
Kimmo

__
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] multiple density plot

2012-03-19 Thread K. Elo

Hi,

some sample data would be *very* helpful...

Kind regards,
Kimmo

16.03.2012 15:44, statquant2 wrote:

Hello I am looking for a special plot.

Let's suppose I have *100 days and
   *each day I have a (1D)
distribution of the same variable.

I would like to plot
*dates on x axis and
*one distribution per date on the y axe. Do you know a way of doing it ?
Cheers


__
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] Re : Adding mean line to a lattice density plot

2012-03-08 Thread K. Elo

Hi,

thank you, Pascal, for your quick reply. Unfortunately your suggestion 
is not working. Please have a look on the attachment, I have added 
manually the mean lines I am trying to plot. The problem with 'abilne' 
seems to be that the argument 'v' is relative to the graph area, not the 
x-axis scale. Thus, plottingat v='mean' won't work...


Any suggestions?

Kind regards,
Kimmo

08.03.2012 09:49, Pascal Oettli wrote:

Hi Kimmo,

You can try to use the layer function from latticeExtra library:

densityplot(~PV1CIV, groups=SGENDER, data=ISGFINC2,
   lwd=2, col=1, lty=c(1,2), pch=c(+,o),
   key=list(text=list(lab=levels(ISGFINC2$SGENDER), col=1),
   space=bottom, columns=2, border=T, lines=T, lwd=2,
   lty=c(1,2), col=1), ref=T, plot.points=F) + 
layer(panel.abline(v=mean(PV1CIV[ SGENDER==1 ])))

Regards,
Pascal
__
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] Re : Re : Adding mean line to a lattice density plot

2012-03-08 Thread K. Elo

HI again,

thanks for the replies. Unfortunately, due to my deadlines, I had no 
time to test Petr's suggestion. I will test it later. I had to figure 
out an alternate solution, so I decided to use normal plotting functions:


 with(subset(ISGFINC2, as.numeric(SGENDER)==1), plot(density(PV1CIV),
  lwd=2, lty=1, ylim=c(0,.006)))
 with(subset(ISGFINC2, as.numeric(SGENDER)==2), lines(density(PV1CIV),
  xlab=, lwd=2, lty=2))
 abline(v=mean(ISGFINC2$PV1CIV[ as.numeric(ISGFINC2$SGENDER)==1 ],
  na.rm=T), col=2, lwd=2, lty=1)
 abline(v=mean(ISGFINC2$PV1CIV[ as.numeric(ISGFINC2$SGENDER)==2 ],
  na.rm=T), col=2, lwd=2, lty=2)

This command sequence produced the plot I was looking for. But since the 
lattice package offers several options not available in normal 
plotting, I am still interested in understanding how to add elements in 
a lattice/trellis plot.


Kind regards,
Kimmo

08.03.2012 16:53, Petr PIKAL wrote:

Hi

You can use this function to add arbitrary line to already plotted lattice
graph.

addLine- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) {
tcL- trellis.currentLayout()
k-0
for(i in 1:nrow(tcL))
   for(j in 1:ncol(tcL))
 if (tcL[i,j]  0) {
k-k+1
 trellis.focus(panel, j, i, highlight = FALSE)
if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else
panel.abline(a=a, b=b, v=v, h=h, ...)
 trellis.unfocus()
 }
}

the usage is similar to abline in base graphics.

addLine(h=some number)

Regards
Petr


__
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] Adding mean line to a lattice density plot

2012-03-07 Thread K. Elo

Hi!

I have used the following command:

densityplot(~PV1CIV, groups=SGENDER, data=ISGFINC2,
  lwd=2, col=1, lty=c(1,2), pch=c(+,o),
  key=list(text=list(lab=levels(ISGFINC2$SGENDER), col=1),
  space=bottom, columns=2, border=T, lines=T, lwd=2,
  lty=c(1,2), col=1), ref=T, plot.points=F)

to produce a lattice density plot presenting the distribution of 
achievment points grouped by the gender of the respondents.


Now, in order to clarify the difference between boys and girls, I would 
like to add two vertical lines: one for the mean of boys, the other for 
the mean of girls. How could I do this (I have tried to use the function 
'panel.abline', but could not figure out how to define the correct 
x-axis point (using 'v=mean(PV1CIV[ SGENDER==1 ])' as a parameter is not 
working...).


Thanks in advance,
Kimmo

__
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] Mlogit missing value problem

2011-12-19 Thread K. Elo

Hi,

19.12.2011 11:12, Ville Iiskola wrote:


Error in if (abs(x - oldx)  ftol) { : missing value where TRUE/FALSE
needed

The reason for this error is in the row 563. There the choice has
value 1 and Ie has missing value. If the choice has value 0 and Ie
has missing values, then there is no errors.

What should i do to make it work..?


How about excluding all rows having the combination choice=1 and 
Ie=NA by using the function 'subset'? Or would this destroy/skew your 
data?


HTH,
Kimmo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help in a project

2011-06-02 Thread K. Elo

Hello,

three commands might do the job (NOTE: df=your data frame, 
obser=Observation, var1=Variable 1 [TYPE: string], var1flag=Variable 1 
flag [TYPE: string])


1. df$var1flag-NA
2. df$var1flag[ is.na(as.numeric(df$var1)) ]-df$var1[ 
is.na(as.numeric(df$var1)) ]

3. df$var1-as.numeric(df$var1)

{Please note: Var1 must be type string at the beginning. Otherwise this 
would not work (you cannot have an A in a numeric column...)]


After this, 'df' gives:

 df
  obser var1 var1flag
1 1 1000 NA
2 2 NAA
3 3  631 NA

Is this what You are looking for?

HTH,
Kimmo

02.06.2011 18:28, Tarun Manchanda wrote:

To whom it may concern,
I am a new user to R and I need help in my if and for statements as I need a 
place marker.

I would like to convert the following table:
Observation | Variable 1
|-
1 | 1
2 | A
3 | 631

Into :
Observation| Variable 1 | Variable 1 Flag
|--|--
1 |  1 | NA
2 | NA | A
3 | 631 | NA


please note |  represents another column.


__
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] Counting

2011-03-17 Thread K. Elo

Dear Jim,

17.03.2011 20:54, Jim Silverton wrote:

I have a matrix say:

23   1
12  12
00
0   1
0   1
0   2
23  2

I want to count of number of distinct rows and the number of disinct element
in the second column and put these counts in a column. SO at the end of the
day I should have:

c(1, 1, 1, 2, 2, 1, 1) for the distinct rows...


Let's suppose my.data is your data frame, var is the 1st column and 
var1 is the second.


1) Create a 3rd columns for the first task:
   my.data$var2-0
2) Count distinct rows:

   for (i in 1:nrow(my.data)) { my.data$var2[i]-nrow(subset(my.data, 
var==var[i]  var1==var1[i])) }


After this, the output of my.data$var2 is:

[1] 1 1 1 2 2 1 1

 ... and c(1, 1, 1, 2, 2, 2, 2) for the counts of how many times the
 elements in the second column exists.

Here I'm a bit irritated. Shouldn't the count for the first element 1 
rather be 3, since the number 3 occurs three times... If this is what 
You are looking for, then the following should work:


1) Create a 4th column for:
   my.data$var3-0
2) Count distinct elements in the second column:

   for (i in 1:nrow(my.data)) { 
my.data$var3[i]-sum(my.data$var1==my.data$var1[i]) }


After this, the output of my.data$var3 is:

[1] 3 1 1 3 3 2 2

HTH,
Kimmo

__
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] (no subject)

2011-02-21 Thread K. Elo
Hi!

21.02.2011 08:50, Schmidt, Lindsey C (MU-Student) wrote:
 What is plot.new? How can I fix this data or add plot.new so it works?

?plot.new
?plot

plot(u[h],v[h],type=l,asp=1) seems to work for me...

HTH,
Kimmo

__
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] Plot

2011-02-21 Thread K. Elo
Hi!

21.02.2011 08:50, Schmidt, Lindsey C (MU-Student) wrote:
 What is plot.new? How can I fix this data or add plot.new so it works?

?plot.new
?plot

plot(u[h],v[h],type=l,asp=1) seems to work for me...

HTH,
Kimmo

__
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] Installation of packages

2011-02-08 Thread K. Elo
Dear Katharina,

08.02.2011 11:21, Katharina Lochner wrote:
 The following appeared on my console:
 
 install.packages(psych)
 
 Warnung in install.packages(psych) :
 
   'lib = C:/PROGRA~1/R/R-212~1.1/library ist nicht schreibbar
 

Apparently You do not have permissions to write to the target directory.
More generally speaking: it seems You do not have permissions to install
software. Maybe You should contact Your system administrator and ask
him/her for help-

HTH,
Kimmo

__
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] test

2011-01-14 Thread K. Elo

Dear Romezo,

a solution maybe not that elegant and effective, but seems to work:

test_calculate-function() {
  tarrow-1
  TARGET-data.frame(Thesis=0, Day=0,A=0,B=0,C=0)
  for (i in c(unique(my.data$Thesis))) {
for (j in c(unique(my.data$Day[ my.data$Thesis==i ]))) {
  TEMPDF-subset(my.data, Thesis==i  Day==j)
  for (k in c(1:(nrow(TEMPDF)-1))) {
for (l in c((k+1):nrow(TEMPDF))) {
  TARGET[tarrow,]-cbind(i,j,(TEMPDF[k,3]-TEMPDF[l,3]), 
(TEMPDF[k,4]-TEMPDF[l,4]), (TEMPDF[k,5]-TEMPDF[l,5]))

  tarrow-tarrow+1
}
  }
}
  }
  print(TARGET)
}

(Please note: my.data is your original data frame)

Kind regards,
Kimmo

__
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] recursive function

2010-06-14 Thread K. Elo
Hi!

Do you mean something like this (df is your original data frame):

--- cut here ---

df1-df
df1[[1]]-paste(R,df[[1]],sep=_)
colnames(df1)-c(SERIES,YEAR,value)
df1$value[ df1$YEAR==2009 ]-5
for (i in c(2009:2007)) { df1$value[ df1$YEAR==(i-1) ]-( df1$value[
df1$YEAR==i ]-df$DELTA[ df$year==i ] ) }

--- cut here ---

Now the output:

 df1
  SERIES YEAR value
1 R_EC01 2006   -19
2 R_EC01 2007-9
3 R_EC01 2008-4
4 R_EC01 2009 5

Please let me know if you were looking for a more general approach
suitable for larger data frames with e.g. several variable classes
(EC01, EC02 etc.)

Kind regards,
Kimmo


--
University of Turku, Finland
Dep. of Political Science and Contemporary history

__
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] barplot (stacked)

2010-03-24 Thread K. Elo

Hi Jens!

23.03.2010 17:18, koj wrote:

The problem is: I want to group the data. I want to have ten groups. The
first two bars should be [1,1] and [2,1] together in one bar and in the
second bar of the first obervation should be [1,2] and [2,2] (stacked with
beside =TRUE). Therefore the first observation is [1,1],[1,2],[2,1] and
[2,2].


I am not sure that I wholly understood what You want :) But why not use 
lattice 'barchart' instead:


Let's suppose 'dm' is your data matrix. Please try the following command 
and let us know, if the output is what you are looking for:


barchart(~dm[,1]+dm[,2], stacked=T)

HTH,
Kimmo

__
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] barplot (stacked)

2010-03-24 Thread K. Elo
Hi Jens!

24.03.2010 14:48, koj wrote
 
 Hi Kimmo, thank you for your answer, but this is not the thing I am searching
 for. Unfortunately, I have not described the problem very good. But just in
 this moment I have a good idea: I use add=TRUE and paint two plots. And so I
 am sure that I can solve the problem. 

Just to satisfy my curiosity: does the following code solve Your problem
(once again, dm refers to your data matrix):

--- cut here ---
barplot(dm[,seq(1,20,2)], col=grey, space=2)
barplot(dm[,seq(2,20,2)], add=T, col=c(blue,green), space=c(3,rep(2,9)))
--- cut here ---

Regards,
Kimmo

__
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 make R plot under Linux

2010-02-22 Thread K. Elo
Hi!

22.02.2010 17:45, xin wei wrote:
 
 thank you for reply. I just type: hist(x) from SSH terminal, expecting a
 histogram to pop up like what i got under windows.instead I got the
 following error msg:
 
 Error in X11(d$display, d$width, d$height, d$pointsize, d$gamma,
 d$colortype,  : 
   unable to start device X11cairo
 In addition: Warning message:
 In function (display = , width, height, pointsize, gamma, bg,  :
   unable to open connection to X11 display ''
 
 Would you give some clues what is going on?

You wrote you are using R over an SSH connection. Have you enabled
X-window support for the connection (see 'man ssh')?

HTH,
-Kimmo

__
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 make R plot under Linux

2010-02-22 Thread K. Elo
Hi!

22.02.2010 19:53, xin wei wrote:
 
 hi, Kevin and K.Elo:
 thank you for the suggestion. Can you be more specific on these? (like how
 exactly get into x-switch or man ssh). I am totally ignorant about linux and
 SSH:( Memory limitation forces me to switch from windows to Linux
 cluster.

Could you provide us with more information about the software you use
for establishing the ssh connection (i.e. your ssh client). I suppose
you are connecting a linux server (having R on it) from a windows
system, aren't you? And you use a ssh client software, right? There
should be an enable X11 forwarding (or something similar) option in
your ssh client application. You should look e.g. in connection settings.

Kind regards,
Kimmo

__
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] Deleting colmuns with 0's and also writing multple csv files

2010-02-19 Thread K. Elo
Hi!

Right, my solution did not take into accound paired negative values
summing up to zero.

This should work in all cases:

df[, which(colSums(df!=0)!=0)]

Kind regards,
Kimmo

__
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] Deleting colmuns with 0's and also writing multple csv files

2010-02-18 Thread K. Elo
Dear Anna,

19.02.2010 08:17, Anna Carter wrote:
 (1) If the dataset contains some variables having all the entries = 0
 and while analysing I want to delete those pericular columns, how do
 acheive this. i.e.

Let's suppose 'df' is your data frame, then:

subset(df, select=which(colSums(df)!=0))

should do the work :)

HTH,
Kimmo

__
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] cbind, row names

2010-01-29 Thread K. Elo
Hi!

29.01.2010 12:49, soeren.vo...@eawag.ch wrote:
 Hello,
 
 I read the help as well as the examples, but I can not figure out why
 the following code does not produce the *given* row names, x and y:
 
 x - 1:20
 y - 21:40
 rbind(
   x=cbind(N=length(x), M=mean(x), SD=sd(x)),
   y=cbind(N=length(y), M=mean(y), SD=sd(y))
 )
 

Maybe because the cbinds in your code produce matrices:

is.matrix(cbind(N=length(x), M=mean(x), SD=sd(x)))
[1] TRUE

Quote ?rbind:
For cbind (rbind) the column (row) names are taken from the colnames
(rownames) of the arguments if these are matrix-like.

HTH,
Kimmo

__
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] Barplots in R

2010-01-15 Thread K. Elo
Hi!

Let's suppose the values for the x axis are stored in 'values'.

barplot(values, col=c(rep(Red,3),rep(1,length(values)-8),rep(Blue,5)))

HTH,
Kimmo

vikrant kirjoitti:
 Suppose I need to draw a Grouped bar plot with 100 values on the X axis. Now
 my question is If I need to highlight suppose first three values by some
 color say 'red' and also I need to highlight last 5 datavalues 
 by some color say 'blue' and the rest of the data in between I need not
 display. Is it possible? If yes How?
 Could anyone explain

__
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] Beginer data.frame

2010-01-12 Thread K. Elo
Hi!

Jean-Baptiste Combes wrote:
 Hello,
 
 I use R 2.10, and I am new in R (I used to use SAS and lately Stata), I am
 using XP.
 
 I have a data which has a data.frame format called x.df (read from a csv
 file). I want to take from this data observations for which the variable
 Code starts with an R. I took all the Code and put them into a vector
 vec-grep(R[A-Z][A-Z],x.df$Code,value=TRUE)


I am not sure if I understood you correctly, but could a simple:

subset(x.df, substring(Code,1,1)==R)

be an appropriate solution?

HTH,
Kimmo

__
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] where does the null come from?

2009-05-13 Thread K. Elo
Hi!

Wacek Kusnierczyk wrote:
 m = matrix(1:4, 2)
 
 apply(m, 1, cat, '\n')
 # 1 2
 # 3 4
 # NULL
 
 why the null?

Could it be the return value of 'cat'. See ?cat, where:

---snip ---
Value
 None (invisible NULL).
---snip ---

Kind regrads,
Kimmo

__
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 read the summary

2009-04-28 Thread K. Elo
Hi!

mathallan wrote:
 How can I from the summary function, decide which glm (fit1, fit2 or fit3)
 fits to data best? I don't know what to look after, so I would please
 explain the important output.

Start with the AIC value (Akaike Information Criterion). The model
having the lowest AIC is the best (of the fitted models, of course).

So, in Your case, the AICs are:

 fit1 - glm(Y~X, family=gaussian(link=identity))
 AIC: 51.294

 fit2 - glm(Y~X, family=gaussian(link=log))
 AIC: 32.954

 fit3 - glm(Y~X, family=Gamma(link=log))
 AIC: 36.65


Hence, the best model seems to be 'fit2'.

Kind regards,
Kimmo

__
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] Deleting rows that contain certain characters...or deleting ANOVA factors

2009-04-22 Thread K. Elo
Hi,

Crosby, Jacy R wrote:
 
 i.e. I'd like to have aov(Phen1~L1) use only Pat1-Pat4,and Pat 10.
  Similarly, aov(Phen1~L2) should use Pat1, 6, and 10.
  Etc.
 
 Is this something I can do in the aov function, or do I need to modify my 
 dataset before running aov? In either case, I need ideas...

Maybe this in your aov formulae:

REG[ -grep([?],REG[,i]), 3+j ]~REG[ -grep([?],REG[,i]),i ]

Kind regards,
Kimmo

__
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 quit this mailing list

2009-03-27 Thread K. Elo
Hi,

 https://stat.ethz.ch/mailman/listinfo/r-help

and there You'll find the section:

To unsubscribe from R-help, get a password reminder, or change your
subscription options enter your subscription email address:

Hope this helps,
Kimmo

__
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] A beginner's question

2009-03-27 Thread K. Elo
Hi,

minben wrote:
 I am a new R-language user. I have set up a data frame mydata,one of
 the colume of which is skill. Now I want to select the observations
 whose skill value is equal to 1,by what command can I get it?

Try this:
mydata1-mydatasubset(mydata, skill==1)

Maybe You should also read this introduction:
http://cran.r-project.org/doc/manuals/R-intro.pdf


Kind regards,
Kimmo

__
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] subset

2009-03-05 Thread K. Elo
Hi Yannick,

yannick misteli wrote:
 I have a vector x with certain ID numbers in it and want to create a
 subset from my dataset Y with this vector i.e extract only the data with
 the given IDs from vector x.
 
 example:
 x
 [1] 10066924 10207314 10257322 10334594 10348247
 
 and now I want to create subset of dataset assignee with
 assignee$pdpass ==  x

Try this:

assignee.1-subset(assignee, pdpass %in% x)

Kind regards,
Kimmo

__
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] filling blanks with NA

2009-01-21 Thread K. Elo
Hi,

kayj wrote:
 Hi,
 
 I do have a data set with some missing values that appear as blanks. I want
 to fill these  blanks with an NA. How can this be done? Thanks for your help

Something like this?

 my.data-data.frame(var=c(1,2,5,,66,4,3,,67,5,3,2,1,4,32,56,23),
stringsAsFactors=F)

 my.data$var
 [1] 1  2  5 66 4  3 67 5  3  2  1
4  32 56 23

 my.data$var[ my.data$var== ] -NA
 my.data$var
 [1] 1  2  5  NA   66 4  3  NA   67 5  3  2  1
4  32 56 23

Kind regards,
Kimmo

__
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] basic boxplot questions

2009-01-16 Thread K. Elo
ivo welch kirjoitti:
 dear R experts:
 
 I am playing with boxplots for the first time.  most of it is
 intuitive, although there was less info on the web than I had hoped.
 
 alas, for some odd reason, my R boxplots have some fat black dots, not
 just the hollow outlier plots.  Is there a description of when R draws
 hollow vs. fat dots somewhere?
 
 [and what is the parameter to change just the size of these dots?]
 
 Also, let me show my fundamental ignorance:  I am a little surprised
 that the average box boxplot would not show the mean and sdv, too, at
 least optionally.  Is there a common way to accomplish this (e.g., in
 a different color), or do I just construct it myself with standard R
 graphics line() commands?
 
 advice appreciated.
 
 regards,
 
 /iaw
 
 __
 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] basic boxplot questions

2009-01-16 Thread K. Elo
Hi Ivo,

ivo welch wrote:
 alas, for some odd reason, my R boxplots have some fat black dots, not
 just the hollow outlier plots.  Is there a description of when R draws
 hollow vs. fat dots somewhere?
 [and what is the parameter to change just the size of these dots?]

Have you tried the command '?boxplot' already? It should help you to
understand the syntax.

 Also, let me show my fundamental ignorance:  I am a little surprised
 that the average box boxplot would not show the mean and sdv, too, at
 least optionally.  Is there a common way to accomplish this (e.g., in
 a different color), or do I just construct it myself with standard R
 graphics line() commands?

Could you post the command(s) you have entered? Without a reproducible
example we are tapping in the dark.

Kind regards,
Kimmo

__
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] Lattice: how to reduce/shrink plot area

2008-09-24 Thread K. Elo
Hi,

is there a command or parameter for reducing the plotting area with
lattice? What I am looking for is an option similar to 'mai' or 'mar'
from the graphs package.

Background: I have plotted several charts with horizontal stacked bars
and now I would like to add info about percentages of each sub bar
beneath the plot (with mtext (?) ). So the plot should look something
like this:

 | AAABBD | 30 35 20 15
 ||
 | AAABBCCDDD | 50 15 15 20
 ||
 | AABBCD | 15 65 10 10

Or is there a better way for achieving what I am looking for?

Thanks in advance for Your help!

Regards,
Kimmo

__
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 print out console output

2008-08-29 Thread K. Elo
Hi,

as mentioned in my previous posting, I run R on a linux machine. So a
possible function for printing (in linux) could look like this:

copy2lpr-function(..., PRINTER=lpr) {
  LPR-pipe(PRINTER,w)
  capture.output(..., file=LPR)
  close(LPR)
}

This seems to work... An allows the user to choose another destination,
options for printing etc.

Thanks for helping!

Kind regards,
Kimmo

__
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 print out console output

2008-08-27 Thread K. Elo

Dear R-helpers,

I am desperately looking for a solution for how to print out the console 
output to a standard printer. For example, I would like to print out the 
summary.lm() output, the output of different ftable-functions etc. I use 
R on a linux machine.


The only ways so far have been to copy-paste the output into an external 
editor or to use sink() to redirect the output into a text file and then 
use shell commands to print out the file. Both ways work but are a bit 
laborious :)


Many thanks in advance for Your help!

Kind regards,
Kimmo

__
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 print out console output

2008-08-27 Thread K. Elo

Hi!

Thanks, Jim, for Your quick answer. But my question was how to 
(re)direct the output to a printer.


Kind regards,
Kimmo


jim holtman wrote:

?capture.output
?sink


x - capture.output(runif(20))



x

[1]  [1] 0.2730090246 0.4462614490 0.2382041477 0.9826505063
0.1556554718 0.3746872961
[2]  [7] 0.6108254879 0.6617410595 0.6694177436 0.4650380281
0.0414420397 0.2307212995
[3] [13] 0.5338913775 0.9186298891 0.0006410333 0.8046684864
0.6205502201 0.5352788521
[4] [19] 0.4255279053 0.7711444888

cat(x, sep=\n)

 [1] 0.2730090246 0.4462614490 0.2382041477 0.9826505063 0.1556554718
0.3746872961
 [7] 0.6108254879 0.6617410595 0.6694177436 0.4650380281 0.0414420397
0.2307212995
[13] 0.5338913775 0.9186298891 0.0006410333 0.8046684864 0.6205502201
0.5352788521
[19] 0.4255279053 0.7711444888


On Wed, Aug 27, 2008 at 7:44 AM, K. Elo [EMAIL PROTECTED] wrote:

Dear R-helpers,

I am desperately looking for a solution for how to print out the console
output to a standard printer. For example, I would like to print out the
summary.lm() output, the output of different ftable-functions etc. I use R
on a linux machine.

The only ways so far have been to copy-paste the output into an external
editor or to use sink() to redirect the output into a text file and then use
shell commands to print out the file. Both ways work but are a bit laborious
:)

Many thanks in advance for Your help!

Kind regards,
Kimmo

__
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] NA value

2008-06-27 Thread K. Elo

Hi,

cimfasy_rwl[ is.na(cimfasy_rwl) ] -0

Or did I understood Your right?

HTH,
Kimmo


Alfredo Alessandrini wrote:

I'm trying to replace NA with 0 value...

I've write a loop, but don't work...

Where's the problem?



cimfasy_rwl

1991 0.92 0.72 0.50 1.29 0.54 1.22
1992 2.15 1.28 1.23 2.26 1.22 3.17
1993 1.50 0.87 1.68 1.97 0.83 2.55
1994 0.69 0.00 0.76 1.89 0.60 0.87
1995 1.13 1.04 1.19 1.52 1.13 1.78
1996 1.15 0.92 1.50 0.97 0.60   NA
1997   NA   NA   NA   NA   NA   NA
1998   NA   NA   NA   NA   NA   NA
1999   NA   NA   NA   NA   NA   NA
2000   NA   NA   NA   NA   NA   NA

files_rwl - ls(pattern=_rwl$)
files_rwl

[1] cimfasy_rwl rocquce_rwl

for (i in files_rwl) assign(i,i[is.na(i)] - 0)
ls()

[1] cimfasy_rwl files_rwl   files.rwl   i   rocquce_rwl

cimfasy_rwl

[1] 0


Thanks in advance,

Alfredo

__
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] MCA in R

2008-06-12 Thread K. Elo

Dear John,

thanks for Your quick reply.


John Fox wrote:
Dear Kimmo,

MCA is a rather old name (introduced, I think, in the 1960s by
Songuist and Morgan in the OSIRIS package) for a linear model
consisting entirely of factors and with only additive effects --
i.e., an ANOVA model will no interactions.


It is true, that MCA is an old name, but the technique itself is still 
robust, I think. The problem I am facing is that I have a research 
project where I try to find out which factors affect measured knowledge 
of a specific issue. As predictors I have formal education, interest, 
gender and consumption of different medias (TV, newspapers etc.). Now, 
these are correlated predictors and running e.g. a simple anova 
(anova(lm(...)) as You suggested) won't - if I have understood correctly 
- consider the problem of correlated predictors. MCA would do this.


A colleague of mine has run anova and MCA in SPSS and the results differ 
significantly. Because I am more familiar with R, I just hoped that this 
marvelous statistical package could handle MCA, too :)



Typically, the results of
an MCA are reported using adjusted means. You could compute these
manually, or via the effects package.


Well, I am interested in the eta and beta values, too. I have tried to 
use the effects package but my attempts with all.effects resulted in 
errors. I have to figure out what's going wrong here :)


Kind regards,
Kimmo Elo

--
University of Turku, Finland
Dep. of political science

__
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] Pros and Cons of R

2008-05-22 Thread K. Elo

Hi,

Monica Pisica wrote:
 - There is no perfect “beginner” book.

How about
- Crawley, Michael (2007). The R book, Wiley  Sons.
- Maindonald, John  John Braun (2007): Data Analysis and Graphics Using 
R (2nd edition), Cambridge University Press.


As a political scientist (with programming experience :) ), both books 
have helped me to decide in favour of R instead of SPSS when I had to 
choose the environment for statistical analysis (in Linux). Sadly 
enough, almost all method books written for social scientists take SPSS 
as the standard statistical application and, consequently, teach data 
analysis in a look-for-this-in-SPSS-output-manner. To use R in social 
sciences, one really must learn how R does things: looking for something 
in the output is not enough :)


BTW, does someone happen to know, if there is any R-book written for 
social scientists?


Kind regards,
Kimmo

__
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] Lattice problems / cannot load lattice

2008-05-06 Thread K. Elo
Hi,

My problem is simple: since having updated the lattice package, I cannot 
load lattice anymore. If I type in the command 'library(lattice)' the 
loading fails with the following message:

--- cut here ---
Error in library.dynam(lib, package, package.lib) : 
  shared library 'lattice' not found
In addition: Warning messages:
1: In loadNamespace(package, c(which.lib.loc, lib.loc), keep.source = 
keep.source) :
  package 'lattice' contains no R code
2: S3 
methods ‘[.shingle’, ‘as.data.frame.shingle’, ‘plot.shingle’, ‘print.shingle’, 
‘summary.shingle’, ‘as.character.shingleLevel’, ‘print.shingleLevel’, 
‘print.trellis’, ‘plot.trellis’, ‘update.trellis’, ‘dim.trellis’, 
‘dimnames.trellis’, ‘dimnames-.trellis’, ‘[.trellis’, ‘t.trellis’, 
‘summary.trellis’, ‘print.summary.trellis’, ‘barchart.formula’, 
‘barchart.array’, ‘barchart.default’, ‘barchart.matrix’, ‘barchart.numeric’, 
‘barchart.table’, ‘bwplot.formula’, ‘bwplot.numeric’, ‘densityplot.formula’, 
‘densityplot.numeric’, ‘dotplot.formula’, ‘dotplot.array’, ‘dotplot.default’, 
‘dotplot.matrix’, ‘dotplot.numeric’, ‘dotplot.table’, ‘histogram.formula’, 
‘histogram.factor’, ‘histogram.numeric’, ‘qqmath.formula’, ‘qqmath.numeric’, 
‘stripplot.formula’, ‘stripplot.numeric’, ‘qq.formula’, ‘xyplot.formula’, 
‘levelplot.formula’, 
[... truncated] 
Error: package/namespace load failed for 'lattice'
--- cut here ---

R-System info:
arch   x86_64
os linux-gnu
system x86_64, linux-gnu
status
major  2
minor  7.0
year   2008
month  04
day22
svn rev45424
language   R
version.string R version 2.7.0 (2008-04-22)

Any hints? Any ideas?

Thanks in advance,
Kimmo
__
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] Lattice problems / cannot load lattice

2008-05-06 Thread K. Elo
Hi,

thanks for the quick reply :)

Prof Brian Ripley kirjoitti viestissään (06.05.2008):
 Try installing again by

 install.packages(lattice, .Library)

 (from an account with suitable privileges).

Tried (as root) - not working :(

 If that still fails, we need to see the output produced during
 installation.

Here we go:
--
 install.packages(lattice, .Library)
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
trying 
URL 'http://cran.ch.r-project.org/src/contrib/lattice_0.17-7.tar.gz'
Content type 'application/x-gzip' length 275240 bytes (268 Kb)
opened URL
==
downloaded 268 Kb

* Installing *source* package 'lattice' ...
** libs
gcc -std=gnu99 -I/usr/lib64/R/include  -I/usr/local/include-fpic  -g -O2 -c 
init.c -o init.o
gcc -std=gnu99 -I/usr/lib64/R/include  -I/usr/local/include-fpic  -g -O2 -c 
threeDplot.c -o threeDplot.o
gcc -std=gnu99 -shared -L/usr/local/lib64 -o lattice.so init.o 
threeDplot.o   -L/usr/lib64/R/lib -lR
** R
** data
**  moving datasets to lazyload DB
** demo
** preparing package for lazy loading
** help
  Building/Updating help pages for package 'lattice'
 Formats: text html latex example
  Lattice   texthtmllatex   example
  Rows  texthtmllatex
  axis.default  texthtmllatex   example
  banking   texthtmllatex   example
  barchart.tabletexthtmllatex   example
  barleytexthtmllatex   example
  cloud texthtmllatex   example
  draw.colorkey texthtmllatex
  draw.key  texthtmllatex
  environmental texthtmllatex   example
  ethanol   texthtmllatex   example
  histogram texthtmllatex   example
  interaction   texthtmllatex   example
  lattice.options   texthtmllatex   example
  latticeParseFormula   texthtmllatex
  level.colors  texthtmllatex   example
  levelplot texthtmllatex   example
  llinestexthtmllatex
  lset  texthtmllatex
  make.groups   texthtmllatex   example
  melanoma  texthtmllatex   example
  onewaytexthtmllatex
  packet.panel.default  texthtmllatex   example
  panel.axistexthtmllatex
  panel.barcharttexthtmllatex
  panel.bwplot  texthtmllatex   example
  panel.cloud   texthtmllatex
  panel.densityplot texthtmllatex
  panel.dotplot texthtmllatex
  panel.functions   texthtmllatex
  panel.histogram   texthtmllatex
  panel.levelplot   texthtmllatex
  panel.number  texthtmllatex
  panel.pairs   texthtmllatex
  panel.paralleltexthtmllatex
  panel.qqmath  texthtmllatex
  panel.qqmathline  texthtmllatex
  panel.stripplot   texthtmllatex
  panel.superpose   texthtmllatex
  panel.violin  texthtmllatex   example
  panel.xyplot  texthtmllatex   example
  prepanel.default  texthtmllatex
  prepanel.functionstexthtmllatex
  print.trellis texthtmllatex   example
  qqtexthtmllatex   example
  qqmathtexthtmllatex   example
  rfs   texthtmllatex   example
  shingles  texthtmllatex   example
  simpleKey texthtmllatex
  simpleTheme   texthtmllatex   example
  singertexthtmllatex   example
  splom texthtmllatex   example
  strip.default texthtmllatex   example
  tmd   texthtmllatex   example
  trellis.devicetexthtmllatex
  trellis.objecttexthtmllatex
  trellis.par.get   texthtmllatex   example
  update.trellistexthtmllatex   example
  utilities.3d  texthtmllatex
  xyplot   

Re: [R] Lattice problems / cannot load lattice

2008-05-06 Thread K. Elo
Prof Brian Ripley kirjoitti viestissään (06.05.2008):
 Does starting R --vanilla help?

 I am wondering if you have another corrupt copy of lattice somewhere.


The latter was the problem, many thanks for this! I use Rkward as GUI 
and obviously some packages have been installed into the user directory 
instead of being installed into the system directory. This messed up 
the installation :( After having deleted the local directory and 
restarted R lattice loaded just fine :)

Once again: many thanks to Brian for his kind help!

Kind regards,
Kimmo

__
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] Data labels in barchart (lattice)

2008-04-21 Thread K. Elo
Dear all,

I use the barchart-function (lattice) for plotting stacked barcharts. 
The data is a summary table (data frame) of likert-scale-evaluations 
(strongly agree, agree...strongly disagree) to different issues 
constructed as follows (L1=precentage of strongly agree evaluations, 
L4=precentage of strongly disagree evaluations):
---
ID  L1  L2  L3  L4  DN
Issue1  25  40  35  0   0
Issue2  15  30  22  28  5
.
.
.
---
What I have so far not achieved is adding data labels to each sub-bar 
of a 100%-bar. What I would like to have is something like this:

Issue1: |###25%###OO40%OOXXX35%XXX
Issue2: | (similar)
...

What should I do in oder to display data labels?

Thanks in advance,
Kimmo

__
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] Data labels in barchart (lattice)

2008-04-21 Thread K. Elo
Hi again,

Deepayan Sarkar wrote (21.4.2008):
 Write your own panel function (which may or may not be a simple
 exercise depending on your level of expertise in R). You could use
 panel.barchart as a starting point. Basically, you need to insert
 some calls to panel.text() (or something equivalent) after calls to
 panel.rect() that draw the bars.

Thanks to Deepayan for his quick answer. Well, I am quite familiar with 
R programming, so programming would not be the issue. What is an issue 
is that I do not (yet) fully understand how the panel-function 
interacts with the calling barchart-function (or vice versa). My 
stacked bar is build of five variables [barchart(ID ~ 
L1+L2+L3+L4+DN ...) ] so the problem is that the data label to be 
displayed is either L1,2,3,4 or DN (for ID, see my first posting).

So the question is: How could I use the current data value used for 
drawing the sub-bar as an argument/variable for/in the 
panel-function?

Many thanks again  greetings,
Kimmo

__
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] using a variable in a subset of a dataframe

2008-04-01 Thread K. Elo
Henrique Dallazuanna wrote (1.4.2008):
 You can try this:

 x - data.frame()
 for(i in LETTERS[1:5]) x[1:10, i] - rnorm(10)
 x

Or this:

--- cut here ---
df-data.frame(0) [obsolet, if df already exists]
for (i in 1:10) { df-data.frame(cbind(df,0)); names(df)
[ncol(df)]-as.character(i) }
--- cut here ---

How 'df' changes:
Step 1:
 df
  X0
1  0

Step 2 (for-loop): 
 df
  X0 1 2 3 4 5 6 7 8 9 10
1  0 0 0 0 0 0 0 0 0 0  0

Is this what You are looking for?

Kind regards,
Kimmo

__
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] SPSS import problem

2008-03-21 Thread K. Elo
Hi,

the problem were a couple of overlength labels, indeed. After having 
removed them, I was able to import the data without any problems. 
Thanks anyway for Your help.

Happy Easter,
Kimmo

__
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.dta for files from stata 9.0

2008-03-18 Thread K. Elo
Hi,

Albrecht Kauffmann wrote (18.03.2008):
 Dear R-helpers,

 if I want to read a .dta-file generated by stata 9.0 with read.dta
 (foreign), I get the message
 not a stata version 5-8 .dta-file. I'm using R-2.6.2 and the latest
 version of the foreign package. Has someone any hint?

Seems quite obvious to me: not a stata version 5-8 means, that the 9.0 
version is not supported. So You should save the file in stata ver. 8 
format and then give a new try.

Hope this helps,
Kimmo

__
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] SPSS import problem

2008-03-12 Thread K. Elo
Dear all,

I have tried to import a SPSS file in R, but always get the following 
message:
--- cut here ---
Error in read.spss(spss-data.sav,  : 
  error reading system-file header
In addition: Warning message:
In read.spss(spss-data.sav,  :
  spss-data.sav: Variable Y6B_A indicates variable label of invalid 
length 256
--- cut here ---

SPSS (ver 14) has no problems with this file.

Any ideas?

Kind regards,
Kimmo

---
University of Turku, Finland
Department of Political Science

__
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] SPSS import problem

2008-03-12 Thread K. Elo
Hi again,

many thanks for Your answers. So, if I understood Wei right:

Zhao, Wei (Cancer Center) wrote (12.3.2008):
 I had a similar problem when read one of my spss.sav with long
 variable label. But when I read another spss.sav with short label the
 same way, I don't have problem.
 Seems like R only allows variable labels of lengths 1...255 as your
 error message showed.

Searching (in SPSS) all variable labels of length  255 and coercing 
them to the length of 255 should solve the problem.

@Brian, who wrote:
 read.spss() is not targetted at such a recent version of SPSS, and
 only allows variable labels of lengths 1...255.

I can save the data in SPSS ver 7 -format, too. Is this version 
supported by the import function?

However, the error message error reading system-file header gives the 
impression that the problem is somewhere else than in the overlength 
labels. Or have I understood something wrong?

Unfortunately, I cannot make the whole data file available. I could make 
a snapshot resulting in the same error - would that be helpful?

Kind regards,
Kimmo

__
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] Combining series of variables using identifier

2008-02-26 Thread K. Elo
Hi,

if the columns always follow the same order (indx,var#, var#_lab ...), 
then You could use the column numbers and do the following:

1) CN-colnames(df)[#] (#=colnum of 'var#')
2) df$NEW-(here the expression to create the new variable)
3) colnames(df)[ncol(df)]-c(paste(CN,new,sep=_))

This can easily be built in a loop.

Hope this helps,
Kimmo

Lauri Nikkinen kirjoitti viestissään (26.02.2008):
 R users,

 I have df like this

 a - data.frame(indx =1:20,
 var1 =rep(c(I20, I40, A50, B60),
 each=5), var1_lab= rep(c(cat, dog, mouse, horse), each=5),
 var2 =rep(c(B20, X40, D50, G60), each=5), var2_lab=
 rep(c(car, bicycle, train, bus), each=5)) str(a)

 I'd like to create new variables by combining varX and varX_lab
 like this:

 a$var1_new - factor(paste(a$var1, a$var1_lab, sep=: ))
 a$var2_new - factor(paste(a$var2, a$var2_lab, sep=: ))
 a

 But, in the real world, I have multiple df:s and many of variables
 named by the same manner. Is there a possibility to create a function
 which combines these variables and creates new ones into the same df
 using varX as an identifier?

 Many thanks,
 Lauri

 __
 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] plotting every ith data point?

2008-02-20 Thread K. Elo
Hi,

this might also work for You:

 points(example.df$StartDate[ (row(example.df)%%5)==0 ], 
example.df$DSR2[ (row(example.df)%%5)==0 ], type=p, pch=3)
 points(example.df$StartDate[ (row(example.df)%%5)==0 ], 
example.df$DSR2[ (row(example.df)%%5)==0 ], type=p, pch=3)

Kind regads,
Kimmo

Jessi Brown wrote (21.02.2008):
 Hello, fellow R enthusiasts.

 Ok, I've been racking my brain about this small issue, and between
 searching the help archives and reading through the plot-related
 documentation, I can't figure out how to achieve my desired endpoint
 without some ugly, brute force coding.

 What I would like to do is make a plot in which only a subset of my
 data are plotted, but in regular intervals, such as every 5th point
 along the sequence. Is anyone aware of a built-in function in plot or
 a related graphing family that can do this, or alternatively, a
 simple way to extract the desired rows from my original dataframe? I
 want to do this because I want to plot multiple series of points with
 their confidence intervals (arrows), and even if I specify type=b,
 the output ends up looking like just a series of crowded points.

 For example, if you try making the plot below, you will see how

 crowded two lines look without error bars:
  example.df-data.frame(StartDate=(94:157), DSR1=seq(0.4, 0.8,
  length.out=64), DSR2=seq(0.3, 0.9, length.out=64))
  plot(example.df$StartDate, example.df$DSR1, type=b,
  ylim=c(0.3,0.9)) points(example.df$StartDate, example.df$DSR2,
  type=b, pch=3)

 Any ideas for an elegant solution to my dilemma?

 Thanks in advance for any help.

 cheers, Jessi Brown

 Ph.D. student
 Program in Ecology, Evolution, and Conservation Biology
 University of Nevada, Reno

 __
 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] plotting every ith data point?

2008-02-20 Thread K. Elo
Hi,

sorry, the correct commands should look like this:
 plot(example.df$StartDate[ (row(example.df)%%5)==0 ], example.df$DSR1[ 
(row(example.df)%%5)==0 ], type=p, ylim=c(0.3,0.9))
 points(example.df$StartDate[ (row(example.df)%%5)==0 ], 
example.df$DSR2[ (row(example.df)%%5)==0 ], type=p, pch=3)

(In my previous mail I had the points twice)

Kind regards,
Kimmo

__
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] simple usage of for

2008-02-19 Thread K. Elo
Hi,

Hans Ekbrand wrote (19.2.2008):
 I tried the following small code snippet which I copied from the

 Introduction to R:
  for (i in 2:length(meriter)) { table(meriter[[1]], meriter[[i]]) }

Try:
for (i in 2:length(meriter)) { print(table(meriter[[1]], 
meriter[[i]])) }

Kind regards,
Kimmo

__
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] data frame question

2008-02-14 Thread K. Elo
Hi,

joseph wrote (15.2.2008):
 Thanks. I have another question:
 In the following data frame df, I want to replace all values in col1
 that are higher than 3 with NA. df= data.frame(col1=c(1:5, NA),col2=
 c(2,NA,4:7))

My suggestion:

x-df$col1; x[ x3 ]-NA; df$col1-x; rm(x)

-Kimmo

__
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] writing a function

2008-02-08 Thread K. Elo
Hi Mohamed,

mohamed nur anisah wrote (8.2.2008):
 Dear lists,

   I'm in my process of learning of writing a function. I tried to
 write a simple functions of a matrix and a vector. Here are the
 codes:

   mm-function(m,n){  #matrix function
  w-matrix(nrow=m, ncol=n)
  for(i in 1:m){
   for(j in 1:n){
w[i,j]=i+j
   }
  }
 return(w[i,j])
 }

This returns the value in row i, in column j, not the matrix. 
Replace 'return(w[i,k]) with just 'w'.

   v-function(n){  #function of a vector
  y=vector(length=n)
   for(i in 1:n){
y[i]=i
   }
  return(y[i])
 }

The same here: the function returns the value of the ith element in the 
vector. Again: Replace 'return(y[i]) with just 'y'.

Please compare the outputs:

 mm-function(m,n) {
+  w-matrix(nrow=m, ncol=n)
+  for(i in 1:m) {
+   for(j in 1:n) {
+ w[i,j]=i+j
+   }
+  }
+ return(w[i,j])
+ }
 mm(5,10)
[1] 15

 mm-function(m,n) {
+  w-matrix(nrow=m, ncol=n)
+  for(i in 1:m) {
+   for(j in 1:n) {
+ w[i,j]=i+j
+   }
+  }
+ w
+ }
 mm(5,10)
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]23456789   1011
[2,]3456789   10   1112
[3,]456789   10   11   1213
[4,]56789   10   11   12   1314
[5,]6789   10   11   12   13   1415

Kind regards,
Kimmo

__
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] Grouping data

2008-01-16 Thread K. Elo
Hi,

I am quite new to R (but like it very much!), so please apologize if 
this is a too simple question.

I have a large data frame consisting of data from a survey. There is, 
for example, information about age and education (a numeric value from 
1-9). Now I would like to extract the total amount of each type of 
education within different age groups (e.g. from 18 to 25, from 25 to 
35 etc.). How could I achieve this? (I have been thinking about 
using 'subset', but if there are better ideas they are welcome :) )

An example might clarify my point. Let's assume the following data:
#   age edu
1   25  2
2   33  5
3   22  3
4   19  1
5   21  3
6   30  4
7   32  4
8   31  1

What I want to have is:

edu 18-25   25-35 ...
1   1   1
2   1   0
3   2   0
4   0   2
5   0   1

Thanks in advance  kind regards,
Kimmo

__
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.