Re: [R] triangular plot

2009-06-12 Thread David Carlson
You may have more luck with the triangle plot functions available in other R libraries. In addition to triangle.plot in ade4, you have other options (this may not be an exhaustive list): plot.acomp in compositions tri in cwhmisc.cwhtool triax in plotrix ternary in StatDA ternaryplot in vcd

Re: [R] plotting multiple variables in 1 bar graph

2012-10-23 Thread David Carlson
If you have your data organized in a matrix like the one printed at the bottom of your jpg, barplot will produce the same graph: set.seed(42) a - matrix(round(runif(45)*100, 0), nrow=5, ncol=9) a [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 91 52 46 94 90 51 74 83

Re: [R] newbie: embeding seq in a list

2012-10-30 Thread David Carlson
Pass a vector to list() instead of individual values: env - list(c(0.8,0.9,1.0,1.1,1.2)) env [[1]] [1] 0.8 0.9 1.0 1.1 1.2 - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message-

Re: [R] group data based on row value

2013-05-23 Thread David Carlson
The OP indicated that the middle group should be closed on both ends, i.e. [0.1, 0.6]. dat2 - rbind(dat, 0.1, 0.6) dat2$group - factor(ifelse(dat2$Var.1, A, ifelse(dat2$Var.6, C, B))) dat2 Var group 1 0.0 A 2 0.2 B 3 0.5 B 4 1.0 C 5 4.0 C 6 6.0 C 7 0.1 B 8 0.6

Re: [R] empty html pages for R-exts and R-intro

2013-05-31 Thread David Carlson
Try again. I'm not having any trouble accessing those pages though the help system or directly by pasting the urls into my browser. - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original

Re: [R] How can I write logical function in R?

2013-05-31 Thread David Carlson
Another possibility: IE - speciesTime1[,-1] - speciesTime2[,-1] Imm - data.frame(addmargins(as.matrix(ifelse(IE0, -1, 0)*IE), 2)) Imm Exti - data.frame(addmargins(as.matrix(ifelse(IE0, 1, 0)*IE), 2)) Exti - David L Carlson Associate Professor of Anthropology

Re: [R] error about MCA

2013-06-03 Thread David Carlson
Probably because you have defined all of the variables as supplemental. These will then be estimated from the other variables, but there are no other variables. --- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX

Re: [R] split and common variables

2013-06-03 Thread David Carlson
It may be easier if you convert the list you provided to a data.frame: dta.df - data.frame(place=dta$place, name=dta$name, value=dta$value) dta.df Note that the last line is blank so you probably want to remove that and remove the blank factor levels: dta.df - dta.df[-nrow(dta.df),]

Re: [R] Y-lim minimum overrun in barplot

2013-06-03 Thread David Carlson
I believe you are looking for the offset= parameter. Consider the following: barplot(c(2, 3), ylim=c(1, 3)) barplot(c(2, 3), ylim=c(1, 3), offset=1) - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352

Re: [R] error about MCA

2013-06-04 Thread David Carlson
. From your words,it seems that the quanti.sup and quali.sup. are not parts of the original variables,but are estimated from the other variables? Many thanks. At 2013-06-03 21:54:59,David Carlson dcarl...@tamu.edu mailto:dcarl...@tamu.edu wrote: Probably because you have defined all

Re: [R] Y-lim minimum overrun in barplot

2013-06-04 Thread David Carlson
at 7:55 AM, David Carlson dcarl...@tamu.edu wrote: I believe you are looking for the offset= parameter. Consider the following: barplot(c(2, 3), ylim=c(1, 3)) barplot(c(2, 3), ylim=c(1, 3), offset=1) - David L Carlson Associate Professor of Anthropology Texas AM

Re: [R] sample {base}

2013-06-05 Thread David Carlson
Something like this? set.seed(42) a - sample.int(10) b - sample.int(5) c - sample.int(3) smpl - function(x) sample(x, ifelse(length(x)5, length(x), 5)) smpl(a) [1] 4 8 1 10 2 smpl(b) [1] 2 3 5 1 4 smpl(c) [1] 2 1 3 - David L Carlson Associate

Re: [R] split and common variables

2013-06-05 Thread David Carlson
places , how can I do it? So, by common I mean, it might be compared with 2, 3, 4 all of them. All possible combinations Many thanks regards Nico On Mon, Jun 3, 2013 at 5:20 PM, David Carlson dcarl...@tamu.edu wrote: It may be easier if you convert the list you provided to a data.frame

Re: [R] combining two different matrizes

2013-06-06 Thread David Carlson
You didn't give us data, but this may give you enough to solve your problem: set.seed(42) nrows - 6 ncols - 5 mat1 - matrix(sample.int(100, 30), nrows, ncols) mat1 [,1] [,2] [,3] [,4] [,5] [1,] 92 70 83 397 [2,] 93 13 23 46 82 [3,] 29 61 40 73 98 [4,]

Re: [R] Remove levels

2013-06-13 Thread David Carlson
Works fine for me. Too bad you didn't include actual data: set.seed(42) DATA - data.frame(UnitName_1=factor(sample(c(lake, pond, river), + 15, replace=TRUE)), Var=sample.int(100, 15)) DATA UnitName_1 Var 1 river 95 2 river 97 3lake 12 4 river 47 5

Re: [R] Remove levels

2013-06-13 Thread David Carlson
Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Carlson Sent: Thursday, June 13, 2013 9:00 AM To: 'Shane Carey'; r-help@r-project.org

Re: [R] Unexpected behavior from hist()

2013-06-13 Thread David Carlson
Density means that the AREAS of the bars add to 1, not the HEIGHTS of the bars. You probably have intervals that are less than 1. Eg: set.seed(42) x - rpois(1000, 5)/100 info - hist(x, prob=TRUE) info $breaks [1] 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 $counts

Re: [R] strange boolean results

2013-06-13 Thread David Carlson
Frequently Asked Questions 7.31 Why doesn't R think these numbers are equal? http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think -these-numbers-are-equal_003f For more details read the First Circle of the R Inferno: http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

Re: [R] NMDS with missing data?

2013-06-17 Thread David Carlson
-Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: Monday, June 17, 2013 12:35 PM To: Elizabeth Beck Cc: David Carlson; r-help@r-project.org Subject: Re: [R] NMDS with missing data? Just wanted to note that one does **not** use prcomp() on the correlation matrix

Re: [R] NMDS with missing data?

2013-06-17 Thread David Carlson
: Elizabeth Beck [mailto:elizabethbe...@gmail.com] Sent: Monday, June 17, 2013 1:43 PM To: Bert Gunter Cc: David Carlson; r-help@r-project.org Subject: Re: [R] NMDS with missing data? Hi Bert David -  I'm putting aside the issues with the missing data for the moment - the NAs are due to not enough

Re: [R] SVMREF infinte number of genes

2013-06-17 Thread David Carlson
It cannot be done because there is not enough time to create the plot. In about a billion years the sun will be 10% brighter than today and the oceans will start to boil away. You will still be plotting genes when that happens. :-( - David -Original

Re: [R] transform 3 numeric vectors empty of 0/1

2013-06-18 Thread David Carlson
Try this set.seed(42) Vec1 - sample(0:1, 15, replace=TRUE) Vec2 - sample(0:1, 15, replace=TRUE) Vec3 - sample(0:1, 15, replace=TRUE) paste0(ifelse(Vec1,A,), ifelse(Vec2,B,), ifelse(Vec3,C,)) [1] ABC ABC AC AB ABC A B ABC AC B A [13] AB C B

Re: [R] Retrieving Labels from vars/cols

2013-06-19 Thread David Carlson
Perhaps you are talking about the variable.labels attribute returned by read.spss in package foreign? If so, you should try the attributes() or the attr() function: ?attributes ?attr - David L Carlson Associate Professor of Anthropology Texas AM University

Re: [R] to build a data.frame

2013-06-19 Thread David Carlson
Try this: aggregate(Project~Country+Iso, df, length) Country Iso Project 1 Burkina Faso BF 2 2 Ethiopia ET 1 3 Ghana GH 1 4 Kenya KE 2 5Madagascar MG 2 6 Mali ML 1 7Mozambique MZ 1 8 Nigeria NG

Re: [R] matching similar character strings

2013-06-21 Thread David Carlson
I think you have to assume there could be other coding errors as well, such as misspellings or abbreviating Street as St. You probably will need to use sub() to correct A2 and possibly A1 before trying to merge. To figure where the problems are, you might try something like this. The last command

Re: [R] Superpose two QQ-plots (gamma distribution) with lattice function qqmath()

2013-06-21 Thread David Carlson
Your rate variable is not a single value, but a vector of 200!. I'm surprised you get anything at all. You have to pick one rate value to use to create the values for the x-axis. For example run rate - 1/4 And then run the qqmath() function. Or, change the rate variable in the ggamma()

Re: [R] hdr.den plot colors help

2013-06-21 Thread David Carlson
You should tell us where hdr.den() comes from as it is not one of the default packages and there are thousands of packages. Some searching suggests you are using package hdrcde. Looking at the source code for hdr.den() it appears that the package author used the default palette in selecting

Re: [R] overlay 2 dot plots

2013-06-21 Thread David Carlson
Maybe something like this? dataset - data.frame(x=c(y, y), y=c(x, z), g=rep(1:2, each=58)) dotplot(x~y, groups=g, data=dataset) - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original

Re: [R] K-means results understanding!!!

2013-06-24 Thread David Carlson
You should read the help page ?kmeans Especially the section labeled Value which tells you what kmeans returns. You will see that the cluster membership is returned as a vector of integers called cluster. If you don't know how to access that from kmeans.results, you haven't read any of the basic

Re: [R] A question on vector

2013-06-25 Thread David Carlson
My_Vector[names(My_Vector)==a] - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Christofer

Re: [R] help with plotmeans (gplots)

2013-06-26 Thread David Carlson
Your data is probably not arranged correctly. See if this works for your data: # Creating a reproducible example set.seed(42) dat - matrix(rnorm(100*15, 5, 5)+rep(1:15, each=100), 15, 100, byrow=TRUE) str(dat) num [1:15, 1:100] 12.85 13 -2 8.98 16.67 ... require(gplots) # Rearranging dat

Re: [R] Creating a matrix with an unknown variable

2013-06-26 Thread David Carlson
Another approach passing both D and delta: Afct - function(D, delta) exp(-(outer(D, D, -)/delta)^2) D - c(-1, -2/3, -1/3, 0, 1/3, 2/3, 1) Delta - 2 Afct(D, delta) - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX

Re: [R] Ifelse leading to inconsistent result

2013-06-26 Thread David Carlson
I don't see that you have set up mutually exclusive ranges. If we modify your code so save the maxlogP and minlogP values: niter = 1e5 # number of iterations is 10^5 CountLoss = rep(0,niter) CountProf = rep (0,niter) maxlogP - rep(0, ninter) minlogP - rep(0, ninter) set.seed(2009) # enables

Re: [R] Data Package Query

2013-06-27 Thread David Carlson
You need to copy the lines you have typed in to R and send them exactly. The only way I get an error message like the one you indicate is with the following: library(data) Error in library(data) : there is no package called 'data' There is no Data function in R so if you typed that you would

Re: [R] Data Package Query

2013-06-27 Thread David Carlson
Refai [mailto:y_re...@hotmail.com] Sent: Thursday, June 27, 2013 11:11 AM To: David Carlson Subject: Re: [R] Data Package Query The same lines as what you typed below and I am getting the same error as what you mentioned below. So what I can do to overcome that problem? Sent using BlackBerryR from

Re: [R] multivariate version of aggregate

2013-06-27 Thread David Carlson
You can pass a matrix to by() set.seed(42) dat - data.frame(x=runif(50)*20, y=runif(50)*20, g=rep(LETTERS[1:2], each=25)) as.vector(by(dat[,1:2], dat$g, function(x) cor(x)[1,2])) [1] -0.05643063 0.16465040 - David L Carlson Associate Professor of

Re: [R] merge dataframes

2013-07-03 Thread David Carlson
In addition to reading Frequently Asked Questions Section 7.31, you should always run your own code before posting. Yours does not work. Spend some time reading one or more of the R tutorials and learn about vectorization. It will save you time and typing. There are many to choose from at

Re: [R] how to choose dates data?

2013-07-04 Thread David Carlson
Also yrs - as.Date(c(2007-01-01, 2009-12-31)) day[day=yrs[1] day=yrs[2]] [1] 2008-04-12 2008-04-12 2008-04-12 Should be fast if there are many days to process since it converts the search criteria, not the data. - David L Carlson Associate Professor of

Re: [R] help on selecting values of an object

2013-07-04 Thread David Carlson
I think this is what you are looking for f - d[match(k, d[,1]), 2] f [1] 4 4 6 6 7 7 6 - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org

Re: [R] Subset and order

2013-07-05 Thread David Carlson
It may be that single and efficient are opposing goals. Two steps lets you create the subset and then just order each query. Alternatively, if the data do not change often, create an ordered version and query that. David Carlson Original Message- From: r-help-boun...@r-project.org

Re: [R] A question on the abline function

2013-07-08 Thread David Carlson
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. First read the instructions for posting. You gave us no data, no code, no example. Just an error message out of context.

Re: [R] Constructing a matrix of outputs from loop

2013-07-08 Thread David Carlson
?outer e.g. output - outer(ap, am, func) - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of

Re: [R] Trouble defining breaks for weighted histogram

2013-07-09 Thread David Carlson
Hard to say without a reproducible example, perhaps by using dput() to include a subset of the data. You should indicate where wtd.hist() comes from since it is not in base R. Perhaps the weights package? It is not clear what weight=weight is unless you have created a variable called weight. If

Re: [R] Replacing values of a matrix with values from corresponding rows of another matrix

2013-07-15 Thread David Carlson
This should also work: mask - randomized 0 mask [,1] [,2] [,3] [,4] [,5] [,6] [1,] FALSE FALSE TRUE FALSE FALSE TRUE [2,] TRUE TRUE FALSE TRUE TRUE TRUE [3,] FALSE TRUE TRUE FALSE FALSE TRUE [4,] TRUE TRUE FALSE TRUE FALSE TRUE randomized[mask] - original[mask] randomized

Re: [R] t-test across columns

2013-07-15 Thread David Carlson
This may be close to what you want: t.val - by(x, x$cat, function(y) if (min(table(y$name)1)) { + t.test(val~name, y)}) t.out - do.call(rbind, sapply(t.val, function(y) c(y$statistic, + p.value=y$p.value))) t.out t p.value p178266580 -0.1156475 0.9144054453

Re: [R] How to open .WTG file Extension in R?

2013-07-17 Thread David Carlson
That reduces the number of possibilities for the file structure to ones that R can probably read, but we need to know more. Try opening a sample file in a text editor to see if it is plain text. If so, you can probably use read.table() or read.csv() to get the file into R. If not, you will need

Re: [R] binary distance measure of the dist function in the stats package

2013-07-18 Thread David Carlson
If you read ?dist, it says that: binary: (aka asymmetric binary): The vectors are regarded as binary bits, so non-zero elements are ‘on’ and zero elements are ‘off’. The distance is the proportion of bits in which only one is on amongst those in which at least one is on. The short answer is

Re: [R] Orders of levels affecting wilcox.test() output

2013-07-18 Thread David Carlson
The short answer is whichever version you want since they are the same. Look at the t-test results, they are also different. In one t is positive and in the other it is negative. That is just a result of whether the smaller mean is subtracted from the larger mean or vice versa. The same is

Re: [R] Changing settings

2013-07-18 Thread David Carlson
Go to Settings | Filters in Gmail and set filters to delete the r-help messages you don't want or move them to a folder for review. R-help messages are not tagged so you cannot restrict them before they are sent. - David L Carlson Associate Professor of

Re: [R] flexible approach to subsetting data

2013-07-23 Thread David Carlson
Actually the .0 on the first variable is not needed. You could modify the reshape() call to search for the base name of each variable so you would not need to change the code if the number of replications changes: reshape(df5, direction=long, v.names=c(dose, resp),

Re: [R] Levels of a factor

2013-07-24 Thread David Carlson
Benchmark is probably a subset from a larger dataframe. R does not automatically remove empty levels but you can do it: set.seed(42) dataset - data.frame(Benchmark=factor(sample(LETTERS[1:26], 50, replace=TRUE), levels=LETTERS[1:26])) levels(dataset$Benchmark) # [1] A B C D E F G H I J K L M

Re: [R] List Structure and Acces to data

2013-07-24 Thread David Carlson
I may not understand, but if you are looking for a way to extract the second item from each list element, you will need to use lapply(): a - list(LETTERS[1:3], 10:12, LETTERS[26:24], 15:13) b - list(LETTERS[4:6], 15:17, LETTERS[23:21], 10:8) c - list(LETTERS[7:9], 20:22, LETTERS[20:18], 5:3) abc

Re: [R] Unable to install packages

2013-07-25 Thread David Carlson
I'd start with the home page for R: http://www.r-project.org/ because you seem to have no idea what version is current (3.0.1). You will find Google to be very helpful. As for manuals, the official documentation is at http://cran.r-project.org/manuals.html and the user contributed manuals are at

Re: [R] transform dataframe with look-up table

2013-07-25 Thread David Carlson
Here's an approach that seems to work. I added an 11th case to your data since you did not have a case where both Left and Right had multiple values in the lookup table. This creates an id value so that we can merge left and right separately and then merge them back together: # Create test data

Re: [R] Maintaining data order in factanal with missing data

2013-07-26 Thread David Carlson
When you use complete.cases(), it creates a logical vector that selects cases with no missing values, but it does not change the rownames in the data.frame and those are carried through to the factor scores so you could link them up that way. Alternatively, you could use na.exclude as the

Re: [R] R function

2013-07-29 Thread David Carlson
Rui has shown you a much more efficient way to code your function in R. To fix the code you posted, you need to add brackets around the loop, test x[i] instead of i (which is always = 1), and get the length of the loop from x not pah1$P. Without the brackets only the first if() is included in the

Re: [R] triangular color plot of array

2013-07-29 Thread David Carlson
A triangular plot can represent three dimensions in a two dimensional plane because the three dimensions are constrained by the fact that they sum to 100% (e.g. sand/silt/clay composition of a soil). That does not seem to apply to your example. It sounds like you might need a 3d contour plot. You

Re: [R] about R stat.table function

2013-07-29 Thread David Carlson
Where did you find out about stat.table()? There is one in package Epi, but who knows if it is the one you are looking for? If you don't know about packages and the library() function, you need to work through a basic tutorial on R. You can't really expect to download a script file and run it

Re: [R] Aggregate

2013-07-29 Thread David Carlson
Or just table(dat1$ID, dat1$Group1) # 0 1 # 1 2 2 # 2 1 3 # 5 1 3 Or xtabs(~ID+Group1, dat1) #Group1 # ID 0 1 # 1 2 2 # 2 1 3 # 5 1 3 Or with labeling dat1$Group1 - factor(dat1$Group1, labels=c(No, Yes)) xtabs(~ID+Group1, dat1) #Group1 # ID No Yes # 1 2 2 # 2

Re: [R] heatmap scale parameter question

2013-07-31 Thread David Carlson
In your example all of the values are drawn from the same distribution so there will not be substantial differences (row means/variances and column means/variances will be approximately the same). set.seed(42) d - matrix(rnorm(100),nrow=20) # Start with your example and modify the row/col means

Re: [R] Correlation Loops in time series

2013-07-31 Thread David Carlson
sapply(1:200, function(x) cor(mts1[,x], mts2[,x], use=complete.obs, method=c(pearson))) - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org

Re: [R] double matrix?

2013-07-31 Thread David Carlson
It is hard to understand that your R code will not work with a double matrix since double is just short for double precision floating point matrix. Your only alternative would be integer. From ?numeric It is a historical anomaly that R has two names for its floating-point vectors, double and

Re: [R] algorithm for clustering categorical data

2013-08-01 Thread David Carlson
Read up on Gower's Distance measures (available in the ecodist package) which can combine numeric and categorical data. You didn't give us any information about how you numerically transformed the categorical variables, but the usual approach is to create indicator variables that code

Re: [R] Conversion of matrix in r to integer

2013-08-01 Thread David Carlson
Assuming you have created a data.frame from the text file you sent that is called RP: str(RP) # 'data.frame': 28597 obs. of 8 variables: # $ gene : chr XLOC_01 XLOC_02 XLOC_03 XLOC_04 ... # $ ZPT.1: num 3516 342 2000 143 0 ... # $ ZPT.0: num 626 82 361 30 0 0 0 0 0 1 ... #

Re: [R] Regression Column names instead of numbers

2013-08-02 Thread David Carlson
It depends on how fancy you want to get. A quick fix would be pairs - paste0(colnames(matrix1), ., colnames(matrix2)) # lapply will be faster since you are returning a list results - lapply(1:200, function(x) summary(lm(formula=matrix1[,x]~matrix2[,x]))) names(results) - pairs results The

Re: [R] could I remove or move points in locator() based on plot()?

2013-08-02 Thread David Carlson
You cannot move or edit them interactively, but you can save the locations of those points by using: a - locator(type=o) # e.g. click on three locations a $x [1] 0.8559376 1.1778126 1.2340626 $y [1] 1.2256976 1.2501162 0.8402324 You could now delete or modify the points and then use lines()

Re: [R] association of multiple variables

2014-02-18 Thread David Carlson
You might modify this function which computes Cramer's V using the assocstats() function in package vcd: catcor - function(x) { require(vcd) nc - ncol(x) v - expand.grid(1:nc, 1:nc) matrix(mapply(function(i1, i2) assocstats(table(x[,i1],

Re: [R] Updating a data frame based on if condition

2014-02-18 Thread David Carlson
Not always true, but it is in this case: ?ifelse David C -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Johnson Sent: Tuesday, February 18, 2014 11:24 AM To: R help Subject: [R] Updating a data frame based on if condition I

Re: [R] Updating a data frame based on if condition

2014-02-18 Thread David Carlson
(ifelse(mydata$FNAME_LENGTH 35, TRUE, FALSE, ifelse(regexpr(9, mydata$FNAME_PATTERN) 0, TRUE, FALSE))) I have the R for Dummies book which covers it a bit, but I just ordered the R Cookbook. On Tue, Feb 18, 2014 at 10:16 AM, David Carlson dcarl...@tamu.edu wrote: Not always true

Re: [R] princomp/prcomp packages not available for 3.0.2

2014-02-19 Thread David Carlson
Both functions (not packages) are included in package stats which is part of the standard R installation. Have you tried? ?prcomp ?princomp - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original

Re: [R] multiplot contour

2014-02-20 Thread David Carlson
Your code produces four line graphs, one above the other. What do you mean by drawing a contour line for the entire panel? A contour map requires three vectors, two for the horizontal position and one for the elevation or height. You have four vectors of y variables with the same x. Since you do

Re: [R] bi-monthly time series

2014-02-20 Thread David Carlson
If the data are two week intervals, the frequency is 52/2 = 26 and that matches the amount of data 8*26=208: vec.ts - ts(vec, start=c(2005, 1), frequency=26) str(vec.ts) Time-Series [1:208] from 2005 to 2013: 1 0 0 0 1 1 1 0 2 0 ... print(vec.ts, calendar=TRUE) p1 p2 p3 p4 p5 p6 p7 p8 p9

Re: [R] Basic question for subset of dataframe

2014-02-27 Thread David Carlson
You have discovered two features of R with your example. Don told you about the first. Data frames are considered to be lists so if you provide only one index, you get the columns (the list elements) when you type str(leadership) 'data.frame': 5 obs. of 10 variables: $ manager: num 1 2 3 4

Re: [R] Conditional polygon colouring

2014-02-28 Thread David Carlson
The simplest way is to use clip(): clip(0, 33, -1, 0) polygon(ff,gg,col=2) clip(0, 33, 0, 1) polygon(ff,gg,col=4) - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From:

Re: [R] A question on graphical representation

2014-03-01 Thread David Carlson
One possibility would be to use the absolute value of the differences. Then they would be all positive: abs(Info$Attr1 - Info$Attr2) [1] 0.46 3.21 0.01 0.99 1.07 10.08 - David L Carlson Department of Anthropology Texas AM University College Station, TX

Re: [R] Having a plot with points and line with different colors

2014-03-05 Thread David Carlson
Alternatively use type=c instead of l which will create line breaks where the points will go. plot(1:5,type=c, col=blue) points(1:5,col=black) David -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Lemon Sent: Wednesday, March

Re: [R] histograms embedded in a plot (as alternative to jitter)

2014-03-05 Thread David Carlson
Not histograms, but here are two alternatives. The first gives you kernel density plots for each value and the second uses violin plots. Both plot points if there are fewer than 5. set.seed(42) y-rpois(500,2) x-rnorm(500,y,1) plot(x,y, type=n) for (i in seq(min(y), max(y), by=1)) { if

Re: [R] Fwd: Using comma as decimal mark in plots

2014-03-07 Thread David Carlson
Does setting OutDec work for you? options(OutDec=,) x - rnorm(50, mean=2, sd=0.1) y - rnorm(50, mean=2, sd=0.2) plot(x, y) # options(OutDec=.) to change it back if you want - David L Carlson Department of Anthropology Texas AM University College Station, TX

Re: [R] Read text file

2014-03-11 Thread David Carlson
If you read the manual page for read.csv (?read.csv), you will see that the default for the header argument is TRUE, but your example has no header. You do not need sep=, because that is the default for read.csv. Also, the default is to convert character strings to factors which you probably do

Re: [R] novice questions

2014-03-11 Thread David Carlson
1. (alfa - X*Y) # Sends the result of the expression to print() 2. Y - datos[,2, drop=FALSE] # see the bracket manual page: ?[ - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From:

Re: [R] creating table with sequences of numbers based on the table

2014-03-13 Thread David Carlson
I think we're down to counting the number of characters in each solution! Arun's 3 two-line versus your two-line solution (not counting loading plyr). How about three short lines? pop - rep(1:nrow(tab), tab$Freq) ind - unlist(sapply(tab$Freq, seq_len)) tab2 - data.frame(pop, ind)

Re: [R] plots

2014-03-14 Thread David Carlson
R-help strips attachments so your post has three problems: 1. No plot to look at 2. No data to replicate your code 3. Email is in html format instead of plain text Try again using plain text mail, copy the results of dput(your.data.frame) into your email and provide code that generates the

Re: [R] Fwd: R basic data manipulation Queries

2014-03-18 Thread David Carlson
Not exactly automatic, but if you are using Windows: 1. Open a blank spreadsheet in Excel 2. write.table(cor(nums2), file=clipboard-128, sep=\t) # In R 3. Paste the clipboard into the spreadsheet Package xlsx can write Excel format files, but does not put them directly into Excel. For the

Re: [R] Reshape large Data Frame to new format

2014-03-24 Thread David Carlson
78023, 43785, 69884, 12840, 54021 are listed as PersonID 3 in rawData, but PersonID 4 in resultData. Here is another way to get there: # Split codes by PersonID creating a single vector for each step1 - split(rawData$codes, rawData$PersonID) # Figure out how many lines we need - here 3 lines

Re: [R] Digits in R

2014-03-25 Thread David Carlson
The digits option gives you the number of significant digits (ignoring leading zeros after the decimal) and it operates on a column by column basis. The first and second columns have values with a leading zero after the decimal (-0.04074 in both columns) so R prints five decimal places to get four

Re: [R] Principal Components Loadings

2014-03-26 Thread David Carlson
Look at the results of summary(body.pc). You will see that the first component accounts for 70% of the variability. That is very large and suggests that the variables are highly correlated with one another. You could check with cor(bodysize). None of the correlations is negative and the smallest

Re: [R] kmeans function

2014-03-26 Thread David Carlson
To add to Ranjan's reply, k-means can potentially find different results with large nstart= numbers in a large data set. But you are correct, with a large enough value, the results will be the same unless there are two solutions that have exactly the same between sum of squares (unlikely but not

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread David Carlson
That only requires two small changes in Sarah's first solution: Finaldata[, !colnames(Finaldata) %in% V$v2[V$v1 == 1]] Length Rate 1 0.53607323 0.01739951 2 0.15405615 0.11837908 3 0.04542388 0.53702702 4 0.15633703 0.68870041 5 0.35293973 0.38258981

Re: [R] generate

2014-03-27 Thread David Carlson
Or tweaking Don's solution but using the original mu and sig vectors: set.seed(42) x.matrix-matrix(0, nrow=27, ncol=5) for(i in 1:27){ + x.matrix[i, ] - rnorm(5, mu[i], sig[i]) + } set.seed(42) xmat - matrix(rnorm(27*5, rep(mu, each=5), rep(sig, each=5)), + nrow=27, byrow=TRUE)

Re: [R] summarizing a dataset on a factor

2014-03-27 Thread David Carlson
It may be possible to do this in a single step, but x1 - aggregate(response~id+age, data, mean) x2 - data[data$eye==l, c(id, response2)] merge(x1, x2) id age response response2 1 1 2 4.60 High 2 2 9 2.65 High 3 3 5 3.65 High 4 4 2 7.55 High 5

Re: [R] match from a data.frame in dependence of an ID

2014-03-28 Thread David Carlson
This is a bit more direct. It works by forcing R to treat test as a matrix rather than a table: tst2 - data.frame(ID=dimnames(test)$ID, as.data.frame.matrix(test), check.names=FALSE) tst2 ID 1 2 3 4 5 10 10 10 20 30 40 50 11 11 0 0 60 70 0 12 12 0 0 0 80 0 rownames(tst2) -

Re: [R] Please help! Matrices and parameter of time

2014-04-01 Thread David Carlson
Use an 3-dimensional array. ?array And any basic introduction to R. - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org

Re: [R] average of rows of each column

2014-04-04 Thread David Carlson
Something like (only 20 columns here): x - matrix(rnorm(120*20), 120, 20) xagg - aggregate(x, list(rep(1:12, each=10)), mean) - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 Original Message- From:

Re: [R] Generate Binary Matrix

2014-04-09 Thread David Carlson
You could randomly assign 1 to a single column in each row and then use binomial draws on the remaining 0's: set.seed(42) dimMat - matrix(0, 1000, 4) dimMat[cbind(1:1000, sample.int(4, 1000, replace=TRUE))] - 1 dimMat[dimMat1] - sample(0:1, 3000, replace=TRUE, prob=c(.6, .4))

Re: [R] reading understanding SVG?

2014-04-21 Thread David Carlson
I was able to grab the logos by bringing the .svg file into Inkscape (open source .svg editor). The three logos are grouped so you can select them and then paste them into another document. Then you'll have to ungroup the three logos and select each logo separately.

Re: [R] find maximum values on the density function of a bimodal distribution

2014-04-21 Thread David Carlson
This will work, as long as there are exactly 2 distinct modes: runs - rle(sign(diff(d.rv$y))) length(runs$lengths) # There should be 4 runs if there are exactly 2 modes [1] 4 mode1 - runs$lengths[1]+1 mode2 - length(d.rv$x)- runs$lengths[4] d.rv$y[c(mode1, mode2)] # The 2 modes: [1]

Re: [R] Hi , Is it possible select a different number of rows by each group with R????

2014-04-21 Thread David Carlson
Look below at your question. R-help does not support html email so you must use plain text if you want to get an answer. - David L Carlson -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Marta

Re: [R] find maximum values on the density function of a bimodal distribution

2014-04-22 Thread David Carlson
...@gene.com] Sent: Monday, April 21, 2014 4:17 PM To: David Carlson Cc: Luigi Marongiu; r-help@r-project.org Subject: Re: [R] find maximum values on the density function of a bimodal distribution Well, yes and no, David. Yours is one possible interpretation -- just work verbatim with the finite

Re: [R] Label customization in R plots

2014-04-28 Thread David Carlson
You can also use the legend() function which will draw the box and arrange the text in a single column (or three columns if you want a single row). It also has shortcuts for positioning the box such as topleft or bottomright. ?legend for more details. - David

Re: [R] descriptive stats by cells in factorial design

2013-08-05 Thread David Carlson
This is a bit simpler. The function quantile() labels the output whereas fivenum() does not: aggregate(Age ~ Generation + Zygosity + Sex + Cohort + ESstatus, data=x, function(x) c(mean=mean(x), sd=sd(x), quantile(x))) - David L Carlson Associate Professor

  1   2   3   >