Re: [R] log transform a data frame

2023-06-13 Thread David Carlson via R-help
= c(0L, 0L > ), Wait.GPU.NB.local = c(0L, 0L), NB.X.F.buffer.ops. = c(7.3, > 4.4), Write.traje = c(0.3, 0.3), Update = c(6.3, 4.3), Constraints = > c(8.9, > 9.7), Comm..energies = c(0.9, 0.9), PIE.redist..X.F = c("8. 1", > "8.7"), PIE.spread = c(29.7, 30.6),

Re: [R] log transform a data frame

2023-06-13 Thread David Carlson via R-help
Your first data column appears to contain character data (e.g. SYCL) which cannot be converted to numeric. You also appear to have 0's in the numeric columns which will cause problems since log(0) is -Inf. Barplots are useful for categorical data, but not continuous, numeric data which are better

Re: [R] Odd behavior of a function within apply

2022-08-09 Thread David Carlson via R-help
Could you have columns that are not character or integer so that y is never defined in the function? count1a(1:5/3) Error in count1a(1:5/3) : object 'y' not found David Carlson On Mon, Aug 8, 2022 at 1:35 PM Erin Hodgess wrote: > OK.⁠​ I'm back again.⁠​ So my test1.⁠​df is 236x390 If I

Re: [R] categorizing data

2022-05-29 Thread David Carlson via R-help
Here is one way to get the table you are describing. First some made up data: dta <- structure(list(tree = c(27, 47, 33, 31, 45, 54, 47, 27, 33, 26, 14, 43, 36, 0, 29, 24, 43, 38, 32, 21, 21, 23, 12, 42, 34), shrub = c(19, 29, 27, 31, 5, 24, 6, 37, 4, 6, 59, 7, 23, 15, 32, 1, 31, 37, 30, 44, 40,

Re: [R] How to obtain named vector from single-column data frame?

2022-05-06 Thread David Carlson via R-help
Just use names(unlist(df[, "VarY", drop=FALSE])) # [1] "VarY1" "VarY2" "VarY3" "VarY4" "VarY5" When you extract a single column from a data frame it converts it to a vector by default. David L Carlson On Fri, May 6, 2022 at 1:05 PM Hooiveld, Guido wrote: > Dear all, I wrote a some code in

Re: [R] legend in plot

2022-05-06 Thread David Carlson via R-help
You can't get exactly what you want with base graphics, but you can get close by defining line types and colors outside the plot command: x <- seq(-3, 3, by = 0.01) lns <- 1:2 clr <- 1:2 matplot(x, cbind(x, x^2), type="l", lty=lns, col=clr) legend("bottomright", legend = c("x", expression(x^2)),

Re: [R] Model To Simulate Dice Roll

2022-04-22 Thread David Carlson via R-help
u so much David! El El vie, 22 de abr. de 2022 a la(s) 11:04 p. > m., David Carlson escribió: Since the rolls are > independent, it is not necessary to separate the rolls into two stages: > sides <- 6 ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ > ZjQcmQRYFpfptBannerStart > This Message Is From an External Send

Re: [R] Row exclude

2022-01-30 Thread David Carlson via R-help
End > Thank you David. > > What about if I want to list the excluded rows? > I used this > (dat3 <- dat1[unique(c(BadName, BadAge, BadWeight)), ]) > > It did not work.The desired output is, > Alex, 20, 13X > John, 3BC, 175 > Jack3, 34, 140 &g

Re: [R] Row exclude

2022-01-29 Thread David Carlson via R-help
t)), ]) > > My concern is when I am applying this for the large data set the "unique" > function may consume resources(time and memory). > > Thank you. > > On Sat, Jan 29, 2022 at 12:30 AM David Carlson wrote: > >> Given that you know which columns

Re: [R] Predictably puzzled.

2021-11-19 Thread David Carlson
All you need is predict(fit, data.frame(x)) or if you had started with a data frame: xy <- data.frame(x, y) fit <- lm(y~x, xy) predict(fit, xy) David Professor Emeritus of Anthropology Texas A University College Station, TX On Fri, Nov 19, 2021 at 8:45 PM Rolf Turner wrote: > > On Fri, 19

Re: [R] Beginner problem - using mod function to print odd numbers

2021-06-06 Thread David Carlson
If the loop is necessary: num <- vector() for (i in 1:100) { if(i %% 2 != 0) num <- c(num, i) } num Or modify your code to this to get each odd number printed on a separate row: for (i in 1:100) { if(i %% 2 != 0) print(i) } David L Carlson On Sun, Jun 6, 2021 at 3:21 PM David C

Re: [R] Beginner problem - using mod function to print odd numbers

2021-06-06 Thread David Carlson
There is really no need for a loop: num <- 1:100 num[ifelse(num %% 2 == 1, TRUE, FALSE)] [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 [26] 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 David L Carlson On Sat, Jun 5, 2021 at 2:05

Re: [R] Variable labels

2021-05-14 Thread David Carlson
You might also look into packages `Hmisc` and `labelVector` that provide some support for labeling variable names. David C On Fri, May 14, 2021 at 1:59 AM PIKAL Petr wrote: > Hallo Steven > > You probably need to be more specific what is your intention. I still > wonder what is the real

Re: [R] Command history

2021-03-01 Thread David Carlson
On the Mac there can be 2 files. The R Studio uses .Rhistory, but Rapp uses .Rapp.history. David L Carlson On Sun, Feb 28, 2021 at 9:06 AM Dr Eberhard W Lisse wrote: > On the Mac it is ~/.Rhistory > > el > > On 2021-02-28 15:39 , Mahmood Naderan-Tahan wrote: > > Hi > > > > May I know where is

Re: [R] Find the ideal cluster

2020-12-12 Thread David Carlson
Look at the Cluster Analysis Task View, particularly section "Additional Functionality" (https://cran.r-project.org/web/views/Cluster.html) Maybe package clValid: The R package clValid contains functions for validating the results of a clustering analysis. There are three main types of cluster

Re: [R] How to save Results in svg format

2020-12-04 Thread David Carlson
an svg file recently into a Google Doc. The 90 pixels > per inch default conversion didn't look very clean and sharp after > imported into a Google Doc. I tried 600 pixels/in and found that Google > Doc looked like it accepted it at first. However, when I went back > later, I found that it h

Re: [R] How to save Results in svg format

2020-12-03 Thread David Carlson
If you look at the examples on the manual pages for the upgma() and NJ() functions you will see that the results are generally sent to the plot() function. To save that graph as an .svg file you need to open a graphics device using the svg() function, plot the data, and close the graphics device.

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread David Carlson
Here is a different approach: xc <- c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c") xn <- as.numeric(gsub("a", ".3", gsub("b", ".5", gsub("c", ".7", xc xn # [1] 1.0 1.3 1.5 1.7 2.0 2.3 2.5 2.7 David L Carlson Professor Emeritus of Anthropology Texas A University On Fri, Jul 10, 2020 at

Re: [R] how to load data frame where numeric will be numeric instead of character

2020-06-01 Thread David Carlson
It might be easier to diagnose if you can show us what the first ten lines in your original file look like. readLines("gokind.nephropathy.fin", n=10) David L Carlson On Mon, Jun 1, 2020 at 6:36 PM Bert Gunter wrote: > Agreed! > > However, there may still be a problem, as read.table()

Re: [R] why outer function is failing?

2020-05-04 Thread David Carlson
1 10 100 David L Carlson Anthropology Department Texas A University On Mon, May 4, 2020 at 2:18 PM David Carlson wrote: > The FUN= argument must be a vectorized function (see the documentation, > ?outer), but the function rolldie takes only scalar values as arguments: > &

Re: [R] why outer function is failing?

2020-05-04 Thread David Carlson
6 elements: only the first used 2: In 1:nsides : numerical expression has 8 elements: only the first used David Carlson Anthropology Department Texas A University On Mon, May 4, 2020 at 1:54 PM Yousri Fanous wrote: > Hello > > From outer help page: > outer takes t

Re: [R] Creating a histogram from a frequency vector - correction!

2019-10-09 Thread David Carlson
Does it have to be a histogram or does it just have to look like one? counts <- c(73,53,42,67,41,50) vals <- c(1,2,3,4,5,6) barplot(counts~vals, space=0) If you want a more histogram-like axis: barplot(counts~vals, space=0, names.arg="") axis(1, 1:6 - .5, 1:6) David L Carlson Anthropology

Re: [R] Plotting in R

2019-07-11 Thread David Carlson
There's a typo in the first column name of your data - "year1" should be "year". Sometimes R will do partial matching and find it, but not always. Is this closer to what you're looking for? plot(rate~year, sydf, type="b", xaxt="n", xlab="Month-Day") axis(1, sydf$year, sydf$month.day) This will

Re: [R] read.xls without row number, column numbers, or factors

2019-07-02 Thread David Carlson
Converting a one-row data frame to a list is not difficult, but there are several ways to represent the data as a list. Here is a possibility: > dta <- data.frame(t(LETTERS[1:10]), stringsAsFactors=FALSE) > dta X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 1 A B C D E F G H I J > dta.lst <-

Re: [R] How to plot dendogram based on samples ID

2019-06-08 Thread David Carlson
Neither ContigID nor sampleID are defined in your example. The default is to plot by the row names. You can get the manual page for the dendrogram plot using the command ?plot.hclust. The second argument lets you specify the labels. David L Carlson, retired Department of Anthropology Texas A

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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] I am new to R

2014-02-13 Thread David Carlson
The official documentation is at http://cran.r-project.org/manuals.html There are also many introductory guides that have been written by R users at http://cran.r-project.org/other-docs.html Including for example: Using R for Data Analysis and Graphics by John Maindonald R for Beginners by

Re: [R] How to write a regression model for finding the radius of a cylinder given height and volume

2014-02-11 Thread David Carlson
?colnames a - matrix(sample.int(10), 5, 2) str(a) int [1:5, 1:2] 10 1 8 6 4 2 7 9 3 5 colnames(a) NULL colnames(a) - c(volume, height) colnames(a) [1] volume height a volume height [1,] 10 2 [2,] 1 7 [3,] 8 9 [4,] 6 3 [5,] 4 5 David C

Re: [R] value on logarithmic axis

2014-02-11 Thread David Carlson
To prevent R from using scientific notation set the scipen option and probably cex.axis to reduce the axis text or some of the tick marks will be skipped: options(scipen=10) plot(x, y, pch=16, type=b, log=x, cex.axis=.8, ylab=expression(bold(Y axis)), xlab=expression(bold(X axis))) To

Re: [R] Problem with metaMDS in vegan

2014-02-10 Thread David Carlson
Without more information, it is hard to say. You did not tell us much about the data beyond the dimensions, but it looks like you have several different kinds of measurements including location and gender (probably categorical) and cuticular profiles (presumably numeric). Without the commands

Re: [R] reversing data axis in stripchart not working?

2014-02-10 Thread David Carlson
You are correct, but I do not know why stripplot works differently from plot. I can give you two ways to get around the problem though. The easiest is to use the plot command to emulate stripchart: plot(x, rep(1, length(x)), xlim=c(2, -2), yaxt=n, ylab=, pch=0) Or using stripchart:

Re: [R] Problem with metaMDS in vegan

2014-02-10 Thread David Carlson
A reproducible example would help. Look at the example in metaMDS using the dune data set. It consists of 20 observations (sites) with 30 species observed (columns). You indicate that your compounds (species) are the rows and your sites are the columns. So perhaps you are analyzing the

Re: [R] How to write a regression model for finding the radius of a cylinder given height and volume

2014-02-10 Thread David Carlson
We have a policy of not doing your homework for you, but I can point you to a valuable resource for learning R http://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf. Your problem involves simple arithmetic. There is no regression problem unless you are trying to predict height from

Re: [R] PCA factominer package, question about changing labels in individuals factor map

2014-01-21 Thread David Carlson
Try rownames(dat) - dat[,1] before running PCA. - David L Carlson Department 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] Mean: category wise within a data frame

2013-12-24 Thread David Carlson
() function: ?aggregate David Carlson -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nandini Jayakumar Sent: Tuesday, December 24, 2013 4:36 AM To: r-help@r-project.org Subject: [R] Mean: category wise within a data frame Hello all I

Re: [R] Inserting color into an irregular grid comprised of polygons

2013-12-23 Thread David Carlson
to convert back. cv - matrix(as.integer(cut(vals, breaks=10)), dim(vals)) pal - heat.colors(10) Then use polygon(x=x, y=y, border=NA, col=pal[cv[k, j]]) Note: border=NA, not NULL David Carlson -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org

Re: [R] Inserting color into an irregular grid comprised of polygons

2013-12-23 Thread David Carlson
I can't think of a straightforward way. You might be able to use the image.plot() function in package fields by using legend.only=TRUE to add the legend to your existing plot. David From: Morway, Eric [mailto:emor...@usgs.gov] Sent: Monday, December 23, 2013 3:46 PM To: dcarl...@tamu.edu

Re: [R] Exporting R graphics into Word without losing graph quality

2013-12-16 Thread David Carlson
This will create a simple plot using Windows enhanced metafile format: win.metafile(TestFigure.emf) plot(rnorm(25), rnorm(25)) dev.off() null device 1 Windows does not read pdf. It will offer to import an eps (encapsulated postscript) file, but it only imports the bitmap

Re: [R] Rows to Column

2013-12-16 Thread David Carlson
Also tbl - xtabs(val~id+cat, dat1) tbl cat id A B C D 1 2 0 4 0 3 0 1 0 0 5 2 0 0 0 6 3 5 2 0 8 0 5 0 2 9 0 0 0 3 To get your column names dimnames(tbl)$cat - paste0(cat, dimnames(tbl)$cat) tbl cat id catA catB catC catD 12040 30100 5

Re: [R] why as.vector can't make x to be a vector?

2013-12-15 Thread David Carlson
According to the documentation (?as.vector), All attributes are removed from the result if it is of an atomic mode, but not in general for a list result. data.frames are lists so is.vector(as.vector(x)) [1] FALSE However if you convert using unlist() or as.matrix(), you will get a vector:

Re: [R] plot two columns against one

2013-12-14 Thread David Carlson
Please do not send emails using html. Please use dput() to send your data to the list st - read.table(text=s, header=TRUE) plot(B~A, st, type=n) with(st, text(A, B, C)) - David L Carlson Department of Anthropology Texas AM University College Station, TX

Re: [R] method default for hclust function

2013-12-13 Thread David Carlson
I think the OP was asking about the agglomeration method in hclust(), not the distance measure in dist(). And the default in dist() is not absolute distance which is not an option, but Euclidean distance: dist(cbind(v, v)) 12345 2 1.414214

Re: [R] extracting non-NA entries from a two-way frequency table

2013-12-13 Thread David Carlson
This will also work: rownames(Geissler) - paste0(b, Geissler$boys) Geissler2 - na.omit(as.data.frame(as.table(as.matrix(Geissler[,-1] names(Geissler2) - c(Boys, Girls, Freq) Geissler2$Boys - as.numeric(substr(as.character(Geissler2$Boys), 2, nchar(as.character(Geissler2$Boys

Re: [R] labels on right y-axis

2013-12-12 Thread David Carlson
I don't see an alternative to text(), but the positioning is not that difficult: oldpar - par(mar=c(5.1, 4.1, 4.1, 4.1)) plot(0) axis(4) text(par(usr)[2], mean(par(usr)[3:4]), TEXT, srt=-90, adj=c(.5,-4), xpd=TRUE) par(oldpar) - David L Carlson

Re: [R] 3-D interpretation

2013-12-10 Thread David Carlson
The error says you have duplicate points in dat so you need to set duplicate= to tell interp() how to handle them. ?interp - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From:

Re: [R] 3-D interpretation

2013-12-10 Thread David Carlson
, I set it equal to the mean. duplicate=mean but still no joy, Thanks On Tue, Dec 10, 2013 at 4:28 PM, David Carlson dcarl...@tamu.edu wrote: The error says you have duplicate points in dat so you need to set duplicate= to tell interp() how to handle them. ?interp

Re: [R] Problem with R colors

2013-12-09 Thread David Carlson
The full details on the col= argument can be found in the section titled Color Specification on the help page for par - ?par. Basically, col= accepts color names, hexadecimal RGB, or an integer designating a position on the current palette. You can get the current palette using palette() [1]

Re: [R] Generating a matrix

2013-12-03 Thread David Carlson
We don't do homework assignments on the list, but one answer requires no loops and an understanding of the various ways R uses vectors for indexing: ?[ - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352

Re: [R] generate multiple probability distributions

2013-12-02 Thread David Carlson
You can use recycling to simplify things: set.seed(42) x - seq(0,12) bin.df - as.data.frame( + rbind( cbind(x, prob=dbinom(x,12,1/6), p=1/6), +cbind(x, prob=dbinom(x,12,1/3), p=1/3), +cbind(x, prob=dbinom(x,12,1/2), p=1/2), +cbind(x,

Re: [R] Days to solstice calculation

2013-12-02 Thread David Carlson
They are a day apart. Summer solstice is day 172 in both cases so the calendar dates should be one day apart and they are (June 22 in 2007 and June 21 in 2008): strptime(2007-06-22, format=%Y-%m-%d)$yday [1] 172 strptime(2008-06-21, format=%Y-%m-%d)$yday [1] 172 Your Daylength() function gives

Re: [R] legend position

2013-12-02 Thread David Carlson
It is not straightforward unless you want the legend in the right or the bottom margins. To put the legend inside the plot region it is simplest to use image() to plot the raster file and then image.plot(legend.only=TRUE) to add the legend. In addition to reading the help page for plot{raster},

Re: [R] error in eval

2013-11-26 Thread David Carlson
And in fact attach(lizards) is included on page 560. You must have left it out of your example code. Without it, your first example would not have run either. - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352

Re: [R] Aggregating spatial data

2013-11-26 Thread David Carlson
Subject: RE: [R] Aggregating spatial data Fantastic. Thanks very much! Is there an easy way to plot the points and the 4 areas? Best, Ioanna -Original Message- From: David Carlson [mailto:dcarl...@tamu.edu] Sent: 25 November 2013 15:21 To: 'IOANNA'; r-help@r-project.org Subject: RE: [R

Re: [R] Aggregating spatial data

2013-11-25 Thread David Carlson
Something like this? s - expand.grid(x=seq(1,100,by=1),y=seq(1,100,by=1)) w - data.frame(x=s$x,y=s$y,z1=rep(c(1,2,3,4),times=length(s$x/4)), + z2=seq(1,length(s$x),by=1)) w$EW - cut(w$x, breaks=c(.5, 50.5, 100.5), labels=c(West, East)) w$NS - cut(w$y, breaks=c(.5, 50.5, 100.5),

Re: [R] convert data frame: two variables into _one_ binary variable

2013-11-25 Thread David Carlson
I think the OP was looking to expand the data frame so that each row was a single observation so that the first row becomes 6 rows, 4-TRUE and 2-FALSE. Something like this womensrole - HSAUR::womensrole step1 - reshape(womensrole, varying=c(agree, disagree), + v.names=Freq, timevar=Agree,

Re: [R] xyz-contour plot (irregular grid)

2013-11-22 Thread David Carlson
I'm not sure if there is a single function, but a quick script would look something like this and would be easily adjusted attach(mtcars) mtcars.ls - loess(mpg~wt*hp) wtg - seq(min(wt), max(wt), length.out=50) hpg - seq(min(hp), max(hp), length.out=50) grid - expand.grid(wt=wtg, hp=hpg) mpg.fit -

Re: [R] data manipulation

2013-11-22 Thread David Carlson
You probably want to use cut(), but as currently stated, your intervals leave gaps (between 20 and 21 for example): set.seed(42) values - runif(25)*100 values [1] 91.480604 93.707541 28.613953 83.044763 64.174552 51.909595 73.658831 [8] 13.40 65.699229 70.506478 45.774178 71.911225

[R] FW: Principal Components in a Linear Model

2013-11-22 Thread David Carlson
Bert is correct. In addition, you are using prcomp() for your principal components analysis so the initial principal component loadings are called rotation in contrast to princomp() where they are called loadings. So you do not have rotated components in the traditional sense of the word. If you

Re: [R] Plotting multiple confidence intervals in the same graph

2013-11-21 Thread David Carlson
Maybe something like this, assuming mean=0: samsize - 100 replicates - 50 pval - .05 samples - replicate(replicates, rnorm(samsize)) confint - t(apply(samples, 2, function(x) c(mean(x)-qt(1-pval/2, df=samsize-1)*sd(x)/sqrt(samsize), mean(x)+qt(1-pval/2,

Re: [R] To transform an adjacency matrix

2013-11-20 Thread David Carlson
indx - arrayInd(which(m0), .dim=c(5, 5)) indx [,1] [,2] [1,]41 [2,]23 [3,]43 [4,]24 [5,]15 # If you want the result sorted indx[order(indx[,1], indx[,2]),] [,1] [,2] [1,]15 [2,]23 [3,]24 [4,]41 [5,]43

Re: [R] Find the cutoff correlation value for Pearson correlation test

2013-11-15 Thread David Carlson
I haven't looked at fBasics::correlationTest, but cor.test uses the t distribution to evaluate significance: t = sqrt(df) * r/sqrt(1 - r^2) where df=n-2 If you solve that for r, you get r = t/sqrt(t^2+100-2) If you choose t as qt(.975, df) for a two-tailed test at p.05 you can plug in t and

Re: [R] R for loop

2013-11-15 Thread David Carlson
I would be easier to respond if we had some idea what Mindreader_2012_vars is, data.frame, list, matrix? Give us a small, reproducible version of what you are trying to accomplish. - David L Carlson Department of Anthropology Texas AM University College

Re: [R] Find the cutoff correlation value for Pearson correlation test

2013-11-15 Thread David Carlson
[mailto:r-help-boun...@r-project.org] On Behalf Of David Carlson Sent: Friday, November 15, 2013 9:42 AM To: 'Jim Lemon'; 'jpm miao' Cc: 'r-help' Subject: Re: [R] Find the cutoff correlation value for Pearson correlation test I haven't looked at fBasics::correlationTest, but cor.test uses the t

Re: [R] Cross Tabulation

2013-11-11 Thread David Carlson
, November 10, 2013 12:52 PM To: dcarl...@tamu.edu Subject: Re: [R] Cross Tabulation Thanks. But I am creating lots of tables and I need Regions and Districts to appear so as to avoid to much editing.   Peter Maclean Department of Economics UDSM On Sunday, November 10, 2013 12:32 PM, David Carlson

Re: [R] Cross Tabulation

2013-11-10 Thread David Carlson
The simplest would be to create a variable combining region and district: data$region_district - with(data, paste(region, district)) prop.table(xtabs(~region_district+response, data), 1) response region_district no yes A d 0.5 0.5 A e 0.0 1.0

Re: [R] Uploading Google Spreadsheet data into R

2013-11-08 Thread David Carlson
Stripping down to the bare essentials seems to get it. In particular making the query just select * instead of select * where B!='' works. You don't need the processing that the more complicated Guardian web page requires. After loading the RCurl package and creating the gsqAPI function:

Re: [R] Fitting multiple horizontal lines to data

2013-11-06 Thread David Carlson
The changepoint package might give you a way to do this. - David L Carlson Department 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

Re: [R] Make Multiple plots in R

2013-10-31 Thread David Carlson
You've left out all the critical code where you set graphics parameters (par()) to place four figures on one page. Probably you have reduced the margins so that there is no room for your labels. Note that xlab is printed but not ylab and there is no space for it.

  1   2   3   >