Re: [R] log transform a data frame

2023-06-13 Thread David Carlson via R-help
Try this pdf("~/graph.pdf") par(mar=c(8, 4, 4, 2)) barplot(d2, legend= c("SYCL", "CUDA"), beside= TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8", "#6a51a3")) dev.off() See ?par to see the details for adjusting margins and other plot features. David On Tue, Jun 13, 2023 at 5

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 h

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 put in

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, 1

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 wh

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)), l

Re: [R] Model To Simulate Dice Roll

2022-04-22 Thread David Carlson via R-help
Sorry, The last three lines should read: all <- apply(results, 1, function(x) length(intersect(x, seq(sides)))==sides) sum(all)/reps results <- as.data.frame(results) To generalize them for values of sides other than 6. On Fri, Apr 22, 2022 at 11:05 PM Paul Bernal wrote: > Thank you so much Da

Re: [R] Row exclude

2022-01-30 Thread David Carlson via R-help
You need to add "-": ` (dat3 <- dat1[-unique(c(BadName, BadAge, BadWeight)), ])` which makes the command NOT). David On Sun, Jan 30, 2022 at 11:00 AM Val wrote: > Thank you David. What about if I want to list the excluded rows? I used > this (dat3 <- dat1[unique(c(BadName, BadAge, BadWeight

Re: [R] Row exclude

2022-01-29 Thread David Carlson via R-help
It is possible that there would be errors on the same row for different columns. This does not happen in your example. If row 4 was "John6, 3BC, 175X" then row 4 would be included 3 times, but we only need to remove it once. Removing the duplicates is not necessary since R would not get confused, b