similar to: R loop problem

Displaying 20 results from an estimated 3000 matches similar to: "R loop problem"

2011 Aug 02
2
Data frame to matrix - revisited
Hi, I've tried to look through all the previous related Threads/posts but can't find a solution to what's probably a simple question. ? I have a data frame comprised of three columns e.g.: ? ID1?ID2?Value a?b?1 b?d?1 c?a?2 c?e?1 d?a?1 e?d?2 ? I'd like to convert the data to a matrix i.e.: ? ?a b c d e a n/a 1 2 1 n/a b 1 n/a n/a 1 n/a? c 2 n/a n/a n/a 1 d 1 1 n/a n/a 2 e n/a n/a 1
2010 Aug 05
2
colour of label points on a boxplot
Hi all, I have 6 datasets(dataframes Assem_ContigsLen7 through all_ContigsLen12) containing 3 columns (contig_id, contig_length, read_count). Each dataset is composed of 3 types of contigs (assemblies of genomic fragments), 1- all Bacterial fragments, 2 - all Viral fragments, 3 - mixed fragments. I identified the type of contig through a merge with another table with just contig_id and
2009 Jul 28
3
selecting vector elements using matrices and combining the results
I've been scratching my head over this one for too long. I'm hoping someone out there can solve this riddle. I have two vectors of characters, v1 and v2, both of length L, and two matrices of logicals, m1 and m2, both of dimension N*L. The first matrix of logicals corresponds to the first vector of characters, and the second to the second. The matrices are telling me which of the
2011 Jun 15
2
Count occurances in integers (or strings)
Hi, I have a dataframe column from which I want to calculate the number of 1's in each entry. Some column values could, for example, be "0001001000" and "11110000111". To get the number of occurrences from a string I use this: sum(unlist(strsplit(mydata[,"my_column"], "")) == "1") However, as my data is not in string form.. How do I convert
2012 Oct 11
2
struggling with R2wd or SWord? Try rtf!
I have been looking for a way to write R-generated reports to Microsoft Word documents. In the past, I used the package R2wd, but for some reason I haven't been able to get it to work on my current set up. R version 2.15.0 (64-bit) Windows 7 Enterprise - Service Pack 1 Microsoft Office Professional Plus 2010 - Word version 14.0.6123.5001 (32-bit) I gave the package
2013 Nov 04
3
Reading data from Excel file in r
Hi experts, I want to read data from an excel data like this: for the fifth column, from first row until 140 but only 1,3,5,7,.....139 (only 70 values), How can I do it in R? thanks [[alternative HTML version deleted]]
2013 Oct 21
3
Error in heatmap
Hi, Could you please help? Heatmap doesn't work with: > heatmap(as.matrix(SPIV2),na.rm = T) Error in hclustfun(distfun(x)) : NA/NaN/Inf in foreign function call (arg 11) There are no 0 data rows or column Thanks a lot Regards --------------------------------------- David
2012 Dec 13
2
replace parenthetical phrases in a string
R-helpers, I have a vector of character strings in which I would like to replace each parenthetical phrase with a single space, " ". For example if I start with x, I would like to end up with y. x <- c("My toast=bog(keep=3 no=4) and eggs(er34)omit=32", "dogs have ears", "cats have tails (and ears, too!)") y <- c("My toast=bog and eggs
2012 Nov 28
7
zeros in double matrix rather than character matrix
Hi, how are you? I have 1000 total columns with 100 rows and I have shown 4 columns of 100 rows below. I want the zeros to be read in as numerical or integer values rather than a character. Right now I have a 100x0 character matrix rather than a 100x1000 double matrix. What do I need to do to read in a .csv spreadsheet with counting the zeros as a numerical or integer value? Thank-you. Irucka
2011 Jun 15
0
specifying interactions in a gam model with "by"
I?m confused by the difference in the fit of a gam model (in package mgcv) when I specify an interaction in different ways. I would appreciate it if someone could explain the cause of these differences. For example: x <- c(105, 124, 124, 124, 144, 144, 150, 176, 178, 178, 206, 206, 212, 215, 215, 227, 229, 229, 229, 234, 234, 254, 254, 290, 290, 303, 334, 334, 334, 344,
2011 Sep 27
2
inset one map on top of another map
I want to overlay a small inset map on top of another map, but I can't figure out how to do it. For example, here are two different maps: # map 1 - Ohio map("state", region= "ohio") # map 2 - US with Ohio darkened map("state") map("state", region="ohio", fill=T, add=T) I would like to add map 2 as a small inset in the corner of map 1. I
2013 Aug 26
1
plot categorical variable with percentage infomation
Dear All, Suppose I have a categorical variable a=as.factor(sample(1:3,10,replace=T)) plot(a) and hist(as.numeric(a),freq=F) would give the histogram of it. But I do not know how to add the counts or percentage information for plot.factor(). hist() can do it but as a numeric variable, the x-axis is not 3 categories in this case. Thank you for any suggestion. Best wishes, Jie
2012 Dec 20
4
comparison of large data set
Hi, how are you? I have the following truncated R code: fileobs <- "MaxFloodDepth_Observed.txt" file1 <- "MaxFloodDepth_1.txt" file2 <- "MaxFloodDepth_2.txt" ... file54 <- "MaxFloodDepth_54.txt" observeddepth = as.matrix(read.ascii.grid(fileobs)$data) observeddepth[observeddepth!=0]<-1 modeldepth1 =
2016 Apr 23
1
subset by multiple letters condition
Thanks Jean, Does anyone know how to set these [hast1] and [hast2] as the colors of a plot? On Friday, April 22, 2016 7:39 AM, "Adams, Jean" <jvadams at usgs.gov> wrote: You can use the grepl() function to give you logicals for each criterion, then combine them as needed. For example: # example version of Command Command <- paste0("_localize_",
2013 Apr 03
4
Better way of writing R code
Dear R forum, (Pl note this is not a finance problem) I have two data.frames as currency_df = data.frame(current_date = c("3/4/2013", "3/4/2013", "3/4/2013", "3/4/2013"), issue_date = c("27/11/2012", "9/12/2012", "14/01/2013", "28/02/2013"), maturity_date = c("27/04/2013", "3/5/2013",
2013 Jul 09
3
fitting log function: errors using nls and nlxb
Hi- I am trying to fit a log function to my data, with the ultimate goal of finding the second derivative of the function. However, I am stalled on the first step of fitting a curve. When I use the following code: FG2.model<-(nls((CO2~log(a*Time)+b), start=setNames(coef(lm(CO2 ~ log(Time), data=FG2)), c("a", "b")),data=FG2)) I get the following error: Error in
2017 Jun 02
0
subletting an array according to dimnames
Have you tried P2["20", "10", "0"] ? Jean On Thu, Jun 1, 2017 at 3:10 PM, li li <hannah.hlx at gmail.com> wrote: > Hi all, > I have a three dimensional array with the corresponding dimension names. > I would like to subset the array according to the dimension names. For > example, > suppose I want to extract the values corresponding to A=20,
2017 Jun 16
0
point size
You could add size = log10_P to the aes() inside geom_point(). Untested code below. See also http://ggplot2.tidyverse.org/reference/geom_point.html ggplot(mydata, aes(x = X, y = log10_P)) + theme_bw() + theme(panel.border=element_blank(), legend.position="top", axis.text=element_text(size = 8)) + geom_point(aes(color = Traits, size = log10_P)) Jean On Fri, Jun 16, 2017 at
2011 Dec 13
2
Plotting a date variable after GAM
Dear All, I am fitting a simple GAM model using the "gam" function in the "mgcv" package. The only independent variable is a continuous variable representing the time of the event (in year and month) coded so that "0" represents January 1960, "1" represents February 1960, etc. Now when I try to plot the results, my x-axis ranges from "-200" to
2017 Jun 01
2
subletting an array according to dimnames
Hi all, I have a three dimensional array with the corresponding dimension names. I would like to subset the array according to the dimension names. For example, suppose I want to extract the values corresponding to A=20, B=10, C=0. I know I can do: P2[dimnames(P2)$A==20, dimnames(P2)$B==10, dimnames(P2)$C==0] But is there a better way for doing this? Thanks for your help! Hanna >