similar to: Process multiple columns of data.frame

Displaying 20 results from an estimated 2000 matches similar to: "Process multiple columns of data.frame"

2007 Nov 22
1
Summary: Process multiple columns of data.frame
Thank you Jim Holtman and Mark Leeds for your help. Original question: >How do I do the following more concisely? > Bout[is.na(Bout$bd.n), 'bd.n'] <- 0 > Bout[is.na(Bout$ht.n), 'ht.n'] <- 0 > Bout[is.na(Bout$dbh.n), 'dbh.n'] <- 0 >. . . Solution: for (i in c('bd.n', 'ht.n', 'dbh.n')) Bout[is.na(Bout[[i]]), i] <- 0 Toy
2008 May 06
2
list manipulation
Hello, I have a set of one-liners (many thanks to previous responses from this list) that I use to look at newly imported data sets with functions like dim(), names(), str(), etc. within lapply(). Generally, these commands work for me but, I am apparently still missing some aspect of list manipulation. I don't understand why I get a set of NULL list elements at the end of each output as
2007 Nov 27
2
str() options
Hello, Is there a way to have str() and ls.str() return all factor levels? Thanx, DaveT. ************************************* Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources david.john.thompson at ontario.ca http://ofri.mnr.gov.on.ca
2008 Feb 12
3
Reorder data frame columns by negating list of names
Hello, I would like to reorder columns in a data frame by their names as demonstrated below: Take this data frame: > xxx <- data.frame(matrix(1:40, ncol=8)) > names(xxx) <- letters[1:8] > xxx a b c d e f g h 1 1 6 11 16 21 26 31 36 2 2 7 12 17 22 27 32 37 3 3 8 13 18 23 28 33 38 4 4 9 14 19 24 29 34 39 5 5 10 15 20 25 30 35 40 and reorder the columns like
2008 Apr 09
3
Changing default plot behaviour
Hello, How would I make the default behaviour of my plots produce output such as the following (i.e. tick marks inside on all axes, labels only on two (arbitrary?) sides) without needing the five additional commands each time? plot(1:10, axes=FALSE) axis(1, tcl=0.5) axis(2, tcl=0.5) axis(3, tcl=0.5, labels=FALSE) axis(4, tcl=0.5, labels=FALSE) box() Thanx, DaveT.
2008 Oct 10
2
Fatal error: unable to restore saved data in .RData
Hello, I am unable to start an R session by double-clicking on an existing .RData file from the Windoze file explorer. A dialogue appears with the message "Fatal error: unable to restore saved data in .RData", and I notice in the R Console the last few lines are: "Loading required package: R2HTML NULL error in function () : unused argument(s) (1:43)" I tried starting
2008 Dec 09
2
assign()ing within apply
Hello, I'm trying to convert a character column in several dataframes to lower case. ### # # Sample data and 'spp' column summaries: # dput(ban.ovs.1993[sample(row.names(ban.ovs.1993), 20), 1:4]) ban.ovs.93 <- structure(list(oplt = c(43L, 43L, 38L, 26L, 35L, 8L, 39L, 1L, 34L, 50L, 10L, 29L, 31L, 24L, 18L, 12L, 27L, 49L, 28L, 51L), rplt = c(NA_integer_, NA_integer_,
2008 Feb 08
1
Can I index a dataframe with a reference from/to a second dataframe?
Hello, I am unable to figure out how to code a new column in a data frame based on an existing column that matches a column in a reference data frame, in a relational-db fashion. I would like this to maintain a minimum set of reference tables that may be reused over several similar datasets. Specifically, I have two data frames as listed below, 'Bos' and 'tree.' For each case in
2008 Jun 19
3
YAPMQ - Yet Another PlotMath Question
Hello, I'm having trouble finding (remembering) how to pass values into text functions in plots, as demonstrated by: slope <- 45 ; plot(1:10) ; text(2, 7, labels = expression(45~degree)) ; text(2, 5, labels = paste(bquote(.(slope)), expression(degree))) Thanx, DaveT. ************************************* Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of
2008 Jan 17
2
Converting plots to ggplot2
Hello Hadley, I am trying to reproduce the following with ggplot: a <- seq(0, 360, 5)*pi/180 ; a ac <- sin(a + (45*pi/180)) + 1 ; ac plot(a, ac, type='b', xaxt = "n") axis(1, at=seq(0,6,1), labels=round(seq(0,6,1)*180/pi),1) abline(v=c(45*pi/180, 225*pi/180)) I can get the basic plot: p <- qplot(a, ac, geom=c('point', 'line')) ;
2008 May 26
1
SciViews and Tinn-R installation problem
Hello, I have just installed R 2.7.0 and re-installed SciViews 0.8-9 and Tinn-R 1.19.4.7 and seem to have broken something along the way as follows. I double-click on my current .RData file in the Windoze explorer, R Console and Tinn-R load successfully (?). I can list objects in my working directory with ls() but, when I attempt to refresh any list in the R explorer tab of the Tools child
2008 Mar 07
1
Finding Interaction and main effects contrasts for two-way ANOVA
I've tried without success to calculate interaction and main effects contrasts using R. I've found the functions C(), contrasts(), se.contrasts() and fit.contrasts() in package gmodels. Given the url for a small dataset and the two-way anova model below, I'd like to reproduce the results from appended SAS code. Thanks. --Dale. ## the dataset (from Montgomery) twoway <-
2008 Apr 10
1
Recovering SPlus GraphSheets
Hello, Is it possible with R to recover the contents of SPlus GraphSheets (*.sgr) without access to SPlus? Also, some of the .sgr files may have multiple pages. Thanx, DaveT. ************************************* Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources david.john.thompson at ontario.ca http://ofri.mnr.gov.on.ca
2007 Dec 20
1
Available environment variables
Hello, I am trying to set my environment to streamline the downloading / updating of packages. I have been through R-intro.html (10.8 Customizing-the-environment), R-FAQ (5.2 How can add-on packages be installed?), rw-FAQ, and help pages for Sys.setenv {base}, download.packages {utils}, etc.,. I am looking for something similar to the download.packages destdir argument on a global environment
2008 Jun 04
1
ggplot questions
Hello, A few questions about the following examples: 1. Why do the two plotting versions not produce the same result? 2. Is the 'scale_x_continuous' (or *_y_* or *_*_discrete) geom the best way to setup grids (as in visual guide-lines) in polar (or for that matter, any) coordinate system? 3. Why do these commands appear to generate 3 plot pages each? 4. Perhaps more questions to follow
2008 Oct 09
1
YALAQ - Yet Another LApply Question
Hello, Two lapply questions (system info and sample data below): 1) Why does the first form of command1 add the name of y _after_ the str() output rather than before as does the second (preferred) form? # command1 version1 invisible(lapply(ls(pattern='bn'), function(y) cat(y, "\n", str(get(y)), "\n") )) # command1 version2 (preferred output)
2004 Dec 10
1
subset bug?
I ran into a problem with "subset" while working at home that I am not sure is a bug or not. I defined a custom function to take a data frame of tree positions, sizes, and types (containing the columns TRT, COMP, PLOT, X, Y, DBH and CON) and wanted to make a stem map of the plot using different symbols and colors to represent the different types of tree stems. I copied a bit of the
2011 Jul 22
1
3d plotting with cloud and wireframe
Hi, I'm trying to plot an equation in two variables to get a feel for sensitivity to its parameters. I've run expand.grid to get made-up vectors of the combinations of the two independent variables, and am trying to plot the output of the dependent, M, against both the dependent in a 3d space. t <- 0:100 DBH <- 10:100 TxDBH<-expand.grid(t,DBH) time<-TxDBH[,1]
2013 Apr 06
1
Plotting a curve for a Holling Type III Functional Response
Hey, So I have a scatter plot and I am trying to plot a curve to fit the data based on a Holling Type III functional response. My function is this: nll2<-function(a,b) { conefun<-(a*DBH^2)/(b^2+DBH^2) nlls2<-dnbinom(x=cones ,size=DBH, mu=conefun,log=TRUE) -sum(nlls) } and my plot is this: plot (DBH,cones) DBH is on the x-axis and cones is on the y-axis. How do I get the curve
2007 Dec 12
1
How to plot the grid figure using R?
Now I have the forest plot data with x, y locations, and I measured the DBH for every indivicuals. The data looks like that: x=runif(100,0,100) y=runif(100,0,100) dbh=runif(100,1,100) rdata=data.frame(x,y,dbh) > rdata[1:5,] x y dbh 1 99.5354145 1.412844 34.10112 2 0.8259361 87.737036 39.12914 3 6.5678613 65.699032 22.55990 4 67.2987881 72.053877 45.83978 5 2.2491372