Re: [R] Variable labels and value labels

2016-05-31 Thread Jim Lemon
Hi Georg, You may find the "add.value.labels" function in the prettyR package useful. Jim On Tue, May 31, 2016 at 10:00 PM, wrote: > Hi All, > > I am using R for social sciences. In this field I am used to use short > variable names like "q1" for question 1, "q2" for question 2 and so on and >

Re: [R] Variable labels and value labels

2016-06-01 Thread Jim Lemon
80+")) age value.labels(age) Jim On Thu, Jun 2, 2016 at 3:37 AM, wrote: > Hi Jim, > > many thanks for the hint. > > When looking at the documentation I did not get how I do control which > value gets which label. Is it possible to define it? > > Kind regards > &

Re: [R] Making an if condition variable ?

2016-06-01 Thread Jim Lemon
Hi ce, a<-10 condition<-expression("a>0") if(eval(parse(text=condition))) cat("a>0\n") Jim On Thu, Jun 2, 2016 at 12:30 PM, ce wrote: > > Dear all, > > I want to make an if condition variable like : > > a = 10 > CONDITION = " a > 0 " > > if ( CONDITION ) print(" a is bigger" ) > > I tried get ,

Re: [R] Cut Dates into bins

2016-06-03 Thread Jim Lemon
Hi Tjun Kiat, This seems to work: daily_date<-as.Date(paste("2000-01",1:28,sep="-"),"%Y-%m-%d") weekly_date<-as.Date(paste(c(1,8,15,22,28),"01/2000",sep="/"), "%d/%m/%Y") cut(daily_date,breaks=weekly_date,include.lowest=TRUE, labels=paste("Week",1:4)) Jim On Fri, Jun 3, 2016 at 6:00 PM, TJUN

Re: [R] Plot half filled circle utf pch

2016-06-03 Thread Jim Lemon
Hi Michael, Have a look at my.symbols in the TeachingDemos package. Jim On Sat, Jun 4, 2016 at 4:19 AM, Michael Weber wrote: > > Dear R users, > > I have been using R for several years and really appreciate all the > developments which have been done. Maybe you can help me with the following >

Re: [R] which function

2016-06-04 Thread Jim Lemon
Hi Gafar, As Jeff has pointed out, the median value may not exist within the dataset. However, this function will give you either the position of the value that is the median, or the position of the two closest values if none equal the median. Be aware that this function may fall victim to the "ind

Re: [R] Reading and converting time data via read.table

2016-06-05 Thread Jim Lemon
Hi EKE, Your problem may be that the date strings are being read as a factor. Try using stringsAsFactors=FALSE when you read the data in. Another way is to convert your dates to strings when passing to as.Date: as.Date(as.character(mydf$Date),"%m/%d/%Y") Jim On Sun, Jun 5, 2016 at 10:53 PM, Ek

Re: [R] find longest consecutive streak in double

2016-06-05 Thread Jim Lemon
Hi Nick, I think you want to get the maximum run length: jja<-runif(92,0,16) med_jja<-median(jja) med_jja [1] 7.428935 # get a logical vector of values greater than the median jja_plus_med<-jja > med_jja # now get the length of runs runs_jja_plus_med<-rle(jja_plus_med) # finally find the maximum r

Re: [R] How to specify a data frame column using command line arg?

2016-06-05 Thread Jim Lemon
Hi Doug, I think this will work for you: adl1<-read.csv("test.csv") adl1[,"a"] [1] 1 4 7 so, adl1[,args[1]] should get you the column that you pass as the first argument. Jim On Mon, Jun 6, 2016 at 5:45 AM, Douglas Johnson wrote: > I'm guessing this is trivial but I've spent two hours searchi

Re: [R] How to specify a data frame column using command line arg?

2016-06-05 Thread Jim Lemon
sample01.csv d j > . > > I can't figure out how to get the column names from the args[] to the > aes(x=?, y=?). > There must be some kind of indirect reference or eval() or substitute() > operator in R but I can't find it. > > Anyway, thanks fo

Re: [R] evaluate the daily mean with date in "POSIXct" "POSIXt" class

2016-06-07 Thread Jim Lemon
Hi Stefano, I might be missing something, but try this: MteBove<-read.table(text="posix_date posix_time snowtemp 2010-01-19 23:30:00 45 NA 2010-01-20 00:30:00 10 2.7 2010-01-20 03:00:00 45 NA 2010-01-20 03:30:00 44 NA 2010-01-20 04:00:00 44 NA 2010-01-20 04:30:00 44 NA 2010-01-20 05:0

Re: [R] Cut Dates into bins

2016-06-08 Thread Jim Lemon
Hi Tjun Kiat, The following examples work for me. One uses the dates you have specified, adding one weekly date to cover the range of your daily dates, otherwise you will generate NAs. The second defines weekly breaks for a year and then simulates daily dates throughout that year. Remember that you

Re: [R] Tree plot with percentages and hierarchies

2016-06-08 Thread Jim Lemon
Hi Joonas, It is easy to display hierarchic classification using either the plot.dendrite or sizetree functions (plotrix). At the moment, they will only display counts, not percentages. It would not be too difficult to reprogram either one to display percentages. Here are examples with shortened ca

Re: [R] apply and cousins

2016-06-08 Thread Jim Lemon
Hi John, With due respect to the other respondents, here is something that might help: # get a vector of values foo<-rnorm(100) # get a vector of increasing indices (aka your "recent" values) bar<-sort(sample(1:100,40)) # write a function to "clump" the adjacent index values clump_adj_int<-functio

Re: [R] Visualize Sparse Matrix.

2016-06-10 Thread Jim Lemon
Hi Francisco, I tried this just to see if it would work. It did, after a while. wtmat<-matrix(rnorm(4602*1817),nrow=4602) library(plotrix) x11(width=5,height=13) color2D.matplot(wtmat,c(1,1,0),c(0,1,0),0,border=FALSE) Jim On Fri, Jun 10, 2016 at 8:27 AM, FRANCISCO XAVIER SUMBA TORAL wrote: > Hi

Re: [R] Visualize Sparse Matrix.

2016-06-10 Thread Jim Lemon
Hi Francisco, Your example plot shows me what you want to do (I think). I'm guessing that you want to display the values in your matrix that are NOT zero or NA, either colored in some way, or just in one color as the example. The following example shows how to do both of these: # wtmat<-matrix(rno

Re: [R] two difficult loop

2016-06-12 Thread Jim Lemon
Hi Greg, You've got a problem that you don't seem to have identified. Your "reg" field in the "map" data frame can define at most 10 unique values. This means that each value will be repeated about 270 times. Unless there are constraints you haven't mentioned, we would expect that in 135 cases

Re: [R] two difficult loop

2016-06-13 Thread Jim Lemon
Hi Greg, Okay, I have a better idea now of what you want. The problem of multiple matches is still there, but here is a start: # this data frame actually contains all the values in ref in the "reg" field map<-read.table(text="reg p rate 10276 0.700 3.867e-18 71608 0.830 4.542e-16 29220 0.430

Re: [R] Binary Value into Text

2016-06-13 Thread Jim Lemon
Hi Fahman, That error message usually means that there is no newline at the end of the last line of the input file. Try adding a newline, Jim On Tue, Jun 14, 2016 at 1:17 AM, Fahman Khan via R-help wrote: > I have written a following piece of code. >> binaryFile <- file("sampleBinary.dat", 'rb'

Re: [R] two difficult loop

2016-06-14 Thread Jim Lemon
) : no non-missing arguments to min; returning Inf >> 2: In max(x) : no non-missing arguments to max; returning -Inf >> >> >> On Mon, Jun 13, 2016 at 3:19 AM, Jim Lemon wrote: >>> >>> Hi Greg, >>> Okay, I have a better idea now of what you want. The

Re: [R] strange error message when using rnorm and rbinom

2016-06-14 Thread Jim Lemon
Hi JI, The most likely problems are negative numbers for sd or "k" being larger than the number of mu.m2 or disp.m2 values. Jim On Wed, Jun 15, 2016 at 4:06 AM, JI Cho wrote: > Dear R users, > > I have been using rnorm, rbinom and have been getting the following warning > message when I do not h

Re: [R] processing time too long

2016-06-14 Thread Jim Lemon
2 columns. file > size is 110 MB.Please guide > me what is wrong. > > Shashi > On Thu, 09 Jun 2016 14:27:17 +0530 Jim Lemon wrote >>Hi Shashi, > > Without trying to go through all that code, your error is something > > simple. When you read in "matrixdata" right

Re: [R] processing time too long

2016-06-14 Thread Jim Lemon
I'm still unsure of what you are attempting to do with this data. First, it is very sparse, appearing to be the counts of occurrences of 2567 strings, some of which are recognizable English words. I suspect that you are trying to get something very simple like the frequency of these strings within

Re: [R] help with r package "trip"

2016-06-15 Thread Jim Lemon
Hi Alice, Have you tried creating a vector of the start position (xpos[1],ypos[1]): xstart<-rep(xpos[1],n) ystart<-rep(ypos[1],n) # where "n" is the number of subsequent positions in the trip max(trackDistance(xstart,ystart,xpos[2:n],ypos[2:n],...)) may then give you the value of the longest dist

Re: [R] benchmark-dea

2016-06-15 Thread Jim Lemon
Hi farzana, Probably the first thing is to ascertain what the class of "farzana" might be: class(farzana) Because "write.csv" expects "the object to be written, preferably a matrix or data frame. If not, it is attempted to coerce x to a data frame." to be the first argument. It seems that "farzan

Re: [R] dplyr's arrange function

2016-06-15 Thread Jim Lemon
Hi Pradip, I'll assume that you are reading the data from a file: pm.df<-read.csv("pmdat.txt",stringsAsFactors=FALSE) # create a vector of numeric values of prevalence numprev<-as.numeric(sapply(strsplit(trimws(pm.df$prevalence)," "),"[",1)) # order the data frame by that vector pm.df[order(numpre

Re: [R] Kendall heat map

2016-06-17 Thread Jim Lemon
Hi Shane, Try the "Kendall" package. Jim On Fri, Jun 17, 2016 at 7:47 PM, Shane Carey wrote: > Hi, > > I was hoping someone could help me. I was wondering are there any libraries > available to undertake a kendall correlation on a matrix of data, in the > same way as what can be undertaken with

Re: [R] replacement has 0 rows, data has 2809

2016-06-18 Thread Jim Lemon
Hi Humberto, The "0 row" error usually arises from a calculation in which a non-existent object is used. I see that you have created a vector with the name "lens" and that may be where this is happening. Have a look at: length(lens) or if it is not too long, just: lens If it is zero length, tha

Re: [R] benchmark-dea

2016-06-19 Thread Jim Lemon
: NULL > $ dual : NULL > $ ux : NULL > $ vy : NULL > $ gamma :function (x) > $ ORIENTATION: chr "in" > $ TRANSPOSE : logi FALSE > $ param : NULL > - attr(*, "class")= chr "Farrell" > > > > > &

Re: [R] R help contingency table

2016-06-20 Thread Jim Lemon
Hi Lucie, You can visualize this using the sizetree function (plotrix). You supply a data frame of the individual choice sequences. # form a data frame of "random" choices coltrans<-data.frame(choice1=sample(c("High","Medium","Low"),100,TRUE), choice2=sample(c("High","Medium","Low"),100,TRUE)) si

Re: [R] replacement has 0 rows, data has 2809

2016-06-20 Thread Jim Lemon
> I need to calculate two normalizations with the vectors lens and cnts, and > have the two options for sorting the normalizations up or down. > > Thanks for any help you can give me to fix this issue. > > Humberto > >> On Jun 18, 2016, at 12:19 AM, Jim Lemon wrote: >

Re: [R] Generate list if sequence form two vector element

2016-06-22 Thread Jim Lemon
Hi Tanvir, Not at all elegant, but: make.seq<-function(x) return(seq(x[1],x[2])) apply(matrix(c(a,b),ncol=2),1,make.seq) Jim On Wed, Jun 22, 2016 at 5:32 PM, Mohammad Tanvir Ahamed via R-help wrote: > Hi, > I want to do the follow thing > > Input : > a <- c(1,3,6,9) > > > b<-c(10,7,20,2) > > >

Re: [R] [FORGED] Re: Generate list if sequence form two vector element

2016-06-22 Thread Jim Lemon
Now why didn't I think of that? apply(matrix(c(a,b),ncol=2),1,function(x)x[1]:x[2]) Jim On Wed, Jun 22, 2016 at 6:14 PM, Rolf Turner wrote: > On 22/06/16 20:00, Jim Lemon wrote: >> >> Hi Tanvir, >> Not at all elegant, but: >> >> make.seq<-function(x) r

Re: [R] What's box() (exactly) doing?

2016-06-23 Thread Jim Lemon
Hi Marius, There are a few things that are happening here. First, the plot area is not going to be the same as your x and y limits unless you say so: # run your first example par("usr") [1] -0.04 1.04 -0.04 1.04 # but plot(NA, type = "n", ann = FALSE, axes = FALSE, xlim = 0:1, ylim = 0:1,xaxs=

Re: [R] How I can calculate the value of response variable

2016-06-26 Thread Jim Lemon
Hi Rezvan, I'll take a guess that you have been presented with a matrix of coefficients. You probably know that a linear model is going to look something like this: Y = ax1 + bx2 + cx3 ... So I will further guess that you want to infer a distribution of Y (the response variable) from more than on

Re: [R] How I can calculate the value of response variable

2016-06-26 Thread Jim Lemon
> winter site1 9.2 2 4 > winter site2 10.2 4 4 > winter site3 11.2 4.5 4 > Would you please tell me how I can do this in R? > > Cheers > > Rezvan > > > -- > *From:* Jim Lemon > *To:* rezvan hatami ; r-help mailing list < > r-help@r-project.org

Re: [R] How I can calculate the value of response variable

2016-06-26 Thread Jim Lemon
am=data1 > > Change the value of fertelizer--à datafram=data2 > > predict(lm(nitrate~0.9*fertilizer2-0.02*flowrate+0.5*rain), datafram=data2 > > Is that better now? > > > > -- > *From:* Jim Lemon > *To:* rezvan hatami ; r-help mailing list

Re: [R] Get the location of a numeric element in a list

2016-06-28 Thread Jim Lemon
Hi Tanvir, How about this: value<-1 (1:length(d))[unlist(lapply(lapply(d,"==",value),any))] Jim On Tue, Jun 28, 2016 at 5:03 PM, Mohammad Tanvir Ahamed via R-help wrote: > Can any one please help me. I will apply this for a very large list, about > 400k vector in a list and vector size is une

Re: [R] Turning a variable name into a function argument

2016-06-28 Thread Jim Lemon
Hi Ken, As far as I can see, ggtitle accepts a single string. The help page is a bit obscure, implying that you can change the title with the "labs" function(?), but using the same explicit string in the "ggtitle" line, perhaps for didactic purposes. You seem to be asking to substitute your own ver

Re: [R] Shorting Matrices

2016-06-28 Thread Jim Lemon
Hi Vasilis, Your question has more to do with telepathy than statistics, but I will attempt an answer anyway. You have in your possession a matrix (perhaps) named Matrix. Within are at least two columns of something, one of which contains dates. You have revealed that the other column contains nume

Re: [R] Bestglm subset analysis

2016-06-29 Thread Jim Lemon
Hi Doug, To expand a bit on what Bert has written, all the the "best subset/best model" procedures use random variation in the dataset to produce a result. This means that you will almost certainly include variables in your "best model" that cannot be replicated. Sometimes you can see this as a var

Re: [R] Writing a formula to Excel

2016-06-30 Thread Jim Lemon
Hi, I don't have excel.link, but have you tried: "=G9*100/G6\n" Jim On Thu, Jun 30, 2016 at 10:34 PM, wrote: > Hi All, > > I am using excel.link to work seemslessly with Excel. > > In addition to values, like numbers and strings, I would like to insert a > full operational formula into a cell.

Re: [R] Command to combine means?

2016-06-30 Thread Jim Lemon
Hi Carlos, The STATA function assumes estimated population SDs. If you have sample SDs you can specify with this: combine<-function(n,mu,sd,sd.type=c("pop","sample")) { N<-sum(n) mean<-sum(n*mu)/N if(sd.type[1]=="sample") { meanss<-(n[1]*(mean-mu[1])^2+n[2]*(mean-mu[2])^2)/N SD<-sqrt(sum(sd

Re: [R] Can I increase the size of an asterisk in plotmath()?

2016-06-30 Thread Jim Lemon
Hi Rolf, A bit of poking around reveals that different fonts have different size asterisks. If you are not already using Times Roman, it might be worth a look. I only have Windows on this (work) PC, so I can't check the Postscript fonts. Jim On Fri, Jul 1, 2016 at 12:50 PM, Rolf Turner wrote: >

Re: [R] lineplot.CI xaxis scale change in sciplot?

2016-07-03 Thread Jim Lemon
Hi Clemence, I don't have sciplot installed, but the help page suggests that the "xaxt" argument is available. This will prevent the x axis from being displayed and you can then specify the x axis you want. Assume that you want an x axis from 0 to 300 by 50: axis(1,at=seq(0,300,by=50)) Jim On T

Re: [R] trouble double looping to generate data for a meta-analysis

2016-07-03 Thread Jim Lemon
Hi Marietta, You may not be aware that the variable k is doing nothing in your example except running the random variable generation 2 or 3 times for each cycle of the outer loop as each successive run just overwrites the one before. If you want to include all two or three lots of values you will h

Re: [R] r code for multilevel latent class analysis

2016-07-07 Thread Jim Lemon
Hi Cristina, Try this: names(mydata) It may be NULL or "ppitrst" may be absent. Jim On Thu, Jul 7, 2016 at 8:26 PM, Cristina Cametti wrote: > Dear all, > > I am not able to find a reliable r code to run a multilevel latent class > model. Indeed, I have to analyze how social trust (three vari

Re: [R] column name changes

2016-07-10 Thread Jim Lemon
Hi Kristi, The period is there for a reason. If you want to extract that column like this: x<-data.frame(a=1:3,b=2:4,c=3:5) > names(x)[3]<-"dif of AB" > x a b dif of AB 1 1 2 3 2 2 3 4 3 3 4 5 > x$dif of AB Error: unexpected symbol in "x$dif of" > x$'dif of AB' [1] 3 4 5

Re: [R] Statistical Test

2016-07-10 Thread Jim Lemon
Hi Julia, You seem to be looking for a test for trend in proportions in the first question. Have a look at this page: http://sphweb.bumc.bu.edu/otlt/MPH-Modules/BS/R/R6_CategoricalDataAnalysis/R6_CategoricalDataAnalysis6.html The second question may require GLMs using experimental condition as a

Re: [R] use value in variable to be name of another variable

2016-07-11 Thread Jim Lemon
Hi Matthew, This question is a bit mysterious as we don't know what the object "chr" is. However, have a look at this and see if it is close to what you want to do. # set up a little matrix of character values tTargTFS<-matrix(paste("A",rep(1:4,each=4),"B",rep(1:4,4),sep=""),ncol=4) # try the assi

Re: [R] graph: horizontal bar reflecting number of data

2016-07-13 Thread Jim Lemon
Hi Tagmarie, This might help: datframe$numberdata<-as.numeric(as.character(datframe$numberdat)) library(plotrix) barcol<-color.scale(datframe$numberdat,extremes=c("black","white")) barplot(matrix(datframe$numberdat,nrow=2,byrow=TRUE), beside=TRUE, horiz=TRUE,names.arg=paste("Week",1:3), col=matr

Re: [R] About "SpatioTemporal" Package

2016-07-13 Thread Jim Lemon
Hi Elham, It looks to me as though you have created the numeric variable "ID" and then passed it to a function that expects it to be a character variable. Try changing the line: ID<-60101:60128 to: ID<-paste("ID",60101:60128,sep="") and see what happens. Jim On Wed, Jul 13, 2016 at 8:29 PM,

Re: [R] Lake Analyzer Help

2016-07-13 Thread Jim Lemon
Hi Kyle, First, see if you can identify which data are getting lost. This will often reveal what is losing them if there is some common characteristic. If not, try to create some toy data (a puddle, not a lake) that will produce the same problem. Then send an email with the toy data as formatted b

Re: [R] About "SpatioTemporal" Package

2016-07-13 Thread Jim Lemon
me > the error. > > Regards, > > > > On Thursday, July 14, 2016 3:10 AM, Jim Lemon wrote: > > > Hi Elham, > It looks to me as though you have created the numeric variable "ID" > and then passed it to a function that expects it to be a character > vari

Re: [R] Please help: cannot import files from Windows into R

2016-07-14 Thread Jim Lemon
Hi Christa, The error messages tell you that the file contains NULL characters, which can cause problems with reading files. You can remove these characters with a "hex editor". I am not familiar with those used on Windows, but look at this Web page: http://alternativeto.net/software/okteta/?platf

Re: [R] graph: horizontal bar reflecting number of data

2016-07-15 Thread Jim Lemon
uot;,"Leon"),3),prop=1) I don't see any other way to put the names on the y-axis that makes any sense. Jim On Fri, Jul 15, 2016 at 5:14 PM, Dagmar wrote: > Dear all, dear Jim, > > Thank you for trying to help Jim. Unfortunately it didn't solve my problem. > >

Re: [R] newbee Caret load question

2016-07-16 Thread Jim Lemon
Hi Lawrence, Try installing pbkrtest on its own: update.packages("pbkrtest") version 0.4.6 is up on CRAN, so this may allow you to make an end run. Jim On Sun, Jul 17, 2016 at 2:06 AM, Lawrence A. Janowitch wrote: > I'm trying to load the caret package in R-Studio (Version 0.99.902) on a > W

Re: [R] How to plot density distribution based on mean values and quantiles in R?

2016-07-18 Thread Jim Lemon
Hi Daniel, Judging by the numbers you mention, the distribution is either very skewed or not at all normal. If you look at this: plot(c(0,0.012,0.015,0.057,0.07),c(0,0.05,0.4,0.05,0),type="b") you will see the general shape of whatever distribution produced these summary statistics. Did the paper

Re: [R] frequency of items

2016-07-20 Thread Jim Lemon
Hi sri, Maybe something like this? has_values<-function(x,values) { if(is.list(x)) { return(sum(unlist(lapply(svlist, function(x,values) return(all(values %in% x)),c(11,12) } } svlist<-list(a=c(11,15,12,25), b=c(11,12), c=c(15,25), d=c(134,45,56), e=46, f=c(45,56), g=c(15,12), h

Re: [R] frequency of items

2016-07-20 Thread Jim Lemon
Oops, didn't translate that function correctly: has_values<-function(x,values) { if(is.list(x)) { return(sum(unlist(lapply(svlist, function(x,values) return(all(values %in% x)),values } } Jim On Wed, Jul 20, 2016 at 7:18 PM, Jim Lemon wrote: > Hi sri, > Maybe somet

Re: [R] plotCI linetypes

2016-07-21 Thread Jim Lemon
;arrows" with calls to "foobars". Obviously "foobars" will only work for vertical bars, but could easily be modified to handle horizontal bars. I think that should be all you need. Jim On Thu, Jul 21, 2016 at 10:05 PM, Jim Lemon wrote: > Hi Florian, > I'll have t

Re: [R] about interpolating data in r

2016-07-22 Thread Jim Lemon
Hi lili, The problem may lie in the fact that I think you are using "interpolate" when you mean "extrapolate". In that case, the best you can do is spread values beyond the points that you have. Find the slope of the line, put a point at each end of your time data (2009-01-01 and 2009-12-31) and us

Re: [R] country fixed effects model with binary dependent variable

2016-07-23 Thread Jim Lemon
Hi Cristina, As Rolf has noted, you probably don't want to persist with "lm" since I think you have dichotomized your initial dependent variable. I also think that you meant "don't worry about the change of variable names" with "how I wrote the variables". I also think that you want to test interac

Re: [R] Ocr

2016-07-26 Thread Jim Lemon
Hi Shane, FreeOCR is a really good place to start. http://www.paperfile.net/ Jim On Wed, Jul 27, 2016 at 6:11 AM, Shane Carey wrote: > Hi, > > Has anyone ever done any ocr in R?? I have some scanned images that I would > like to convert to text!! > Thanks > > > -- > Le gach dea ghui, > Shane >

Re: [R] Ocr

2016-07-26 Thread Jim Lemon
my own script for this as I have many > images/ pdf's in a folder and would like to batch process them using an R > script!! > Thanks > > > On Tuesday, July 26, 2016, Jim Lemon wrote: >> >> Hi Shane, >> FreeOCR is a really good place to start. >> >>

Re: [R] change the colour line in gamm4 plotting

2016-07-26 Thread Jim Lemon
Hi Maria, The "plot.gam" function doesn't use the "col" argument for lines, but does change the color of points in the second example on the help page. There doesn't seem to be an easy way to change the function to get what you want. Jim On Tue, Jul 26, 2016 at 11:47 PM, Maria Lathouri via R-hel

Re: [R] Subtraction with aggregate

2016-07-28 Thread Jim Lemon
Hi Gang, This is one way: gangdat<-read.table(text="subject QMemotion yi s1 75.1017 neutral -75.928276 s2 -47.3512 neutral -178.295990 s3 -68.9016 neutral -134.753906 s1 17.2099 negative -104.168312 s2 -53.1114 negative -182.373474 s3 -33.0322 negative -137.

Re: [R] Extract data

2016-07-28 Thread Jim Lemon
Hi Roslina, Try this: aggbalok_mth[aggbalok_mth$year %in% 2009:2014,] Jim On Fri, Jul 29, 2016 at 1:12 PM, roslinazairimah zakaria wrote: > Dear r-users, > > I would like to extract year from 2009 to 2014 with the corresponding month > and rain amount. > > I tried this: > aggbalok_mth[aggbalo

Re: [R] Extract data

2016-07-29 Thread Jim Lemon
class = "data.frame") > > Thank you. > > On Fri, Jul 29, 2016 at 2:30 PM, roslinazairimah zakaria > wrote: >> >> I have one more question, how do I get the sum for the years. Thank you. >> >> On Fri, Jul 29, 2016 at 12:36 PM, roslinazairimah zakaria

Re: [R] store result of loop in df

2016-07-29 Thread Jim Lemon
Hi Alain, You are probably storing the result, replicated five times, in df$VAR. Each cycle of the loop replaces the last value with the current value. If you really want the entire output of binom.test in the last column: multi.binom.test<-function(xs,ns) { reslist<-list() for(i in 1:length(xs

Re: [R] How to Display Value Labels in R Outputs?

2016-07-30 Thread Jim Lemon
Hi Courtney, I haven't seen any answers to your question, and perhaps it is because others, like I, were unable to open the file you attached. The uninformative labels you are getting may be the names of values or the character value of factors. Is there a sample data set from the original file tha

Re: [R] Read output:

2016-08-02 Thread Jim Lemon
Hi Roslina, As we do not know whether the file actually exists, all I can do is to suggest that you look in your file manager (Windows Explorer, probably) and see if the file is where you think it is. The problem is most likely a spelling error somewhere in the path or filename. Jim On Tue, Aug

Re: [R] Multiple plot in a page

2016-08-03 Thread Jim Lemon
Hi Roslina, You only specify space for two plots in: par(mfrow=c(1,2)) However, you only try to plot two plots, so I will assume that you only want two. You haven't defined "x" in the above code, which will cause an error. The code below gives me two plots as I would expect (I made up the data th

Re: [R] Error code 100 when using the function “fitdist” from the fitdistrplus package

2016-08-04 Thread Jim Lemon
Hi Nelly, The message David suggested was about scaling the values, not adjusting the parameters. It is quite possible that the empirical distribution is nothing like beta or Weibull. Have you tried plotting the values with "density"? Jim On Fri, Aug 5, 2016 at 6:56 AM, Nelly Reduan wrote: > He

Re: [R] difftime in years

2016-08-04 Thread Jim Lemon
Hi Thomas, Be aware that if you are attempting to calculate "birthday age", it is probably better to do it like this: bdage<-function(dob,now) { dobbits<-as.numeric(unlist(strsplit(dob,"/"))) nowbits<-as.numeric(unlist(strsplit(now,"/"))) return(nowbits[3]-dobbits[3]- (nowbits[2] wrote: > dif

Re: [R] Fwd: only plot borders of a region in a scatter plot

2016-08-04 Thread Jim Lemon
Hi Zun Yin, The first problem requires something like this: pixel8<-function(x,y,pixsize=1) { nsteps<-length(x)-1 newx<-x[1] newy<-y[1] for(i in 1:nsteps) { dx<-diff(x[i:(i+1)]) dy<-diff(y[i:(i+1)]) if(dx && dy) { newx<-c(newx,x[i]+dx,x[i]+dx) newy<-c(newy,y[i],y[i]+dy) } else

Re: [R] Fwd: only plot borders of a region in a scatter plot

2016-08-04 Thread Jim Lemon
[i+1]) newy<-c(newy,y[i+1]) } lastdx<-dx lastdy<-dy } return(list(x=newx,y=newy)) } x<-c(5,4,4,3,2,2,1,1,2,2,3,4,5,5,6,6,7,8,8,9,8,7,7,6,6,5,5) y<-c(1,2,2,3,4,4,5,6,6,7,8,8,9,8,8,7,7,6,6,5,5,4,3,3,2,2,1) plot(1:9,type="n") lines(x,y) newxy<-pixel8(x,y) lines(n

Re: [R] SAS file

2016-08-06 Thread Jim Lemon
Hi Yuan, Your file didn't make it. The error message you got is generally due to a misspelt filename or to the file not being where you think it is. Jim On Fri, Aug 5, 2016 at 8:10 PM, Yuan Jian via R-help wrote: > Hello,I have a SAS formatted file as attached, when I use lookup.xport i got >

Re: [R] R help

2016-08-06 Thread Jim Lemon
Hi Vladimir, Do you want something like this? vdat<-read.table(text="numberoftweet,tweet,locations,badwords 1,My cat is asleep,London,glum 2,My cat is flying,Paris,dashed 3,My cat is dancing,Berlin,mopey 4,My cat is singing,Rome,ill 5,My cat is reading,Budapest,sad 6,My cat is eating,Amsterdam,ann

Re: [R] R help

2016-08-07 Thread Jim Lemon
nd when I try to > names(unlist(sapply(vdat$tweet,grep,pattern=badwords))) there is a mistake. > I had this question before but do you know by any chance how to separate > just those words in a column badwords and not include NA's or blanks. > > Thank you, > Vladimir > > 2016-0

Re: [R] Conditionally remove rows with logic

2016-08-08 Thread Jim Lemon
Hi Jennifer, A very pedestrian method, but I think it does what you want. remove_rows_after_1<-function(x) { nrows<-dim(x)[1] rtr<-NA rtrcount<-1 got1<-FALSE thisID<-x$ID[1] for(i in 1:nrows) { if(x$ID[i] == thisID && got1) { rtr[rtrcount]<-i rtrcount<-rtrcount+1 } if(x$ID[i] !=

Re: [R] Visualising multiple temporal periods each with an associated value

2016-08-08 Thread Jim Lemon
Hi Loris, This looks a lot like a Gantt chart with variable bar widths. I'll check it when I have a bit of time and repost. JIm On Mon, Aug 8, 2016 at 6:12 PM, Loris Bennett wrote: > Hi, > > I want to visualise temporal events as rectangles, one side of the > rectangle being the length of the e

Re: [R] Visualising multiple temporal periods each with an associated value

2016-08-08 Thread Jim Lemon
time evolves. That approach would not allow rectangles to expand over time, but that could be accommodated. It's more complicated than either of the two, but I think it can be done. Jim On Tue, Aug 9, 2016 at 8:19 AM, Jim Lemon wrote: > Hi Loris, > This looks a lot like a Gantt chart wi

Re: [R] Calendar embedded for event scheduling

2016-08-09 Thread Jim Lemon
Hi Sri Ram, Do you mean that you want to produce a Gantt chart? Have a look at the example for gantt.chart in the plotrix package. Jim On Wed, Aug 10, 2016 at 2:58 PM, Sriram Kumar wrote: > Dear all, > > i am presently doing the r codes for developing the shiny app fro my > professional ,i ne

Re: [R] need some help with date

2016-08-14 Thread Jim Lemon
;-paste(x,collapse="/") return(xdate) } newx<-as.Date(sapply(xbits,long_year,new_century),"%m/%d/%Y") return(newx) } Jim On Mon, Aug 15, 2016 at 10:47 AM, Jim Lemon wrote: > Hi Glenn, > Perhaps this will help: > > dateCentury<-function(x,new_century=20

Re: [R] [R Survey Analysis] Problem counting number of responses

2016-08-16 Thread Jim Lemon
Hi Lauren, As Sarah noted, if your blank responses are coming as NAs, it may be best to leave them alone until you have done the calculations: survey$responses<-!is.na(survey[,c("q1","q2","q3")]) survey$sum_survey<-rowSums(survey[,c("q1","q2","q3")],na.rm=TRUE) # the next line returns a logical ve

Re: [R] remove rows based on row mean

2016-08-18 Thread Jim Lemon
Hi Adrian, Try this: sm$rowmeans<-rowMeans(sm[,2:length(sm)]) sm<-sm[order(sm$Gene,sm$rowmeans,decreasing=TRUE),] sm[-which(duplicated(sm$Gene)),] Jim On Fri, Aug 19, 2016 at 7:33 AM, Adrian Johnson wrote: > Hi Group, > I have a data matrix sm (dput code given below). > > I want to create a da

Re: [R] pheatmap breaks

2016-08-20 Thread Jim Lemon
Hi Adrian, I had to add an extra color, but this might do what you want: chxx<-matrix(runif(100,-3.32,4.422),nrow=10) chxx.cut<-as.numeric(cut(chxx,breaks=c(-3.5,-1.96,-1,0,1,1.96,5))) chxx.col<-c("#FF","#FF","#FF","#FF","#FF",NA)[chxx.cut] library(plotrix) chxx_highcol<-color.

Re: [R] I had 1 problem with r

2016-08-22 Thread Jim Lemon
Hi SuBin, This seems to work: emp<-read.table(text="empno,ename,job,mgr,hiredate,sal,comm,deptno 7369,SMITH,CLERK,7902,1980-12-17,800,,20 7499,ALLEN,SALESMAN,7698,1981-02-20,1600,300,30 7521,WARD,SALESMAN,7698,1981-02-03,1250,500,30 7566,JONES,MANAGER,7839,1981-03-02,2975,,20 7654,MARTIN,SALE

Re: [R] aggregate

2016-08-23 Thread Jim Lemon
Hi Gang Chen, If I have the right idea: for(zval in levels(myData$Z)) crossprod(as.matrix(myData[myData$Z==zval,c("X","Y")])) Jim On Wed, Aug 24, 2016 at 8:03 AM, Gang Chen wrote: > This is a simple question: With a dataframe like the following > > myData <- data.frame(X=c(1, 2, 3, 4), Y=c(4, 3

Re: [R] function that converts data into a form that can be included in a question to mailing list

2016-08-24 Thread Jim Lemon
Hi John, I think it is "dput". Jim On Thu, Aug 25, 2016 at 8:00 AM, John Sorkin wrote: > > There is a function that can be used to convert data structures such as a > data frame into a different format that allows the data to be sent to the > mailing list. The structure that is created can be

Re: [R] Storing business hours

2016-08-25 Thread Jim Lemon
Hi Alexander, A time series comes to mind, but perhaps all you need is a matrix with 0s for closed and 1s for open. Each row is a shop. Column names as the times and the resolution is up to you. I think colSums will produce what you want. Jim On Fri, Aug 26, 2016 at 1:10 AM, alexander.som...@tu-d

Re: [R] Exponential population model

2016-08-29 Thread Jim Lemon
Hi Josephine, Given the parameters you describe, you will probably have to write a function to update the database of animals at regular intervals. You can then run a number of repeats to get a better estimate of the final populations. I tried this and it appears to work. I don't know of any existi

Re: [R] Looping through different groups of variables in models

2016-08-31 Thread Jim Lemon
Hi Kai, Perhaps something like this: kmdf<-data.frame(group=rep(c("exp","cont"),each=50), time=factor(rep(1:5,20)), condition=rep(rep(c("hot","cold"),each=25),2), value=sample(100:200,100)) for(timeindx in levels(kmdf$time)) { for(condindx in levels(kmdf$condition)) { cat("Time",timeindx,"Co

Re: [R] Same code on Mac?

2016-09-01 Thread Jim Lemon
Sometimes the problem stems from chronic exposure to user interfaces. Yesterday I prepared some material for a Mac user's presentation and said, "This text file tells you the names of the files you need for the presentation" the response was, "Can I click on it?" I deleted all the files in the

Re: [R] readBin documentation error

2016-09-02 Thread Jim Lemon
Hi Yucheng, Have a look at "An Introduction to R" (get there with "help.start()"), section : 3.1 Intrinsic attributes: mode and length The distinction between numeric and integer modes in R may not be obvious, but it is important at times. Jim On Fri, Sep 2, 2016 at 5:47 AM, Yucheng Song via R

Re: [R] Creating a loop with code from the mblm package

2016-09-04 Thread Jim Lemon
Hi Bailey, Treat it as a guess, but try this: for (i in c(1:3)){ y<-mydata[,i] x <- mblm(y ~ Year, mydata, repeated = FALSE) print(x) } I'm not sure that you can mix indexed columns with column names. Also, Year is column 4, no? Jim On Sun, Sep 4, 2016 at 11:43 AM, Bailey Hewitt wrote: > H

Re: [R] Error in reading subset of data from CSV file

2016-09-04 Thread Jim Lemon
Hi Christofer, You have embedded commas in your data structure. This is guaranteed to mess up a CSV read. Jim On Sun, Sep 4, 2016 at 5:54 PM, Christofer Bogaso wrote: > Hi again, > > I was trying to read a subset of Data from a CSV file using below code > as example : > > library(sqldf) > > Dat

Re: [R] Error in reading subset of data from CSV file

2016-09-04 Thread Jim Lemon
I suppose you could try quote=TRUE Jim On Sun, Sep 4, 2016 at 8:13 PM, Christofer Bogaso wrote: > Thanks Jim. But my data is like that and I have to live with that. Any > idea on workaround. Thanks, > > On Sun, Sep 4, 2016 at 3:40 PM, Jim Lemon wrote: >> Hi Christofer, &g

Re: [R] Error in reading subset of data from CSV file

2016-09-04 Thread Jim Lemon
Shouldn't get that with write.csv. Jim On Sun, Sep 4, 2016 at 9:29 PM, Christofer Bogaso wrote: > Didnt work getting unused argument error. > > On Sun, Sep 4, 2016 at 4:47 PM, Jim Lemon wrote: >> I suppose you could try quote=TRUE >> >> Jim >>

<    1   2   3   4   5   6   7   8   9   10   >