Re: [R] Looking for simple line-splitting code

2025-02-05 Thread Mohammad Tanvir Ahamed via R-help
x <- c("abc\ndef", "", "ghi") unlist(strsplit(gsub("^$", "\n", x), "\n")) or  x %>%   gsub("^$", "\n", .) %>%   strsplit("\n") %>%   unlist() Regards. Tanvir Ahamed Stockholm, Sweden |  mashra...@yahoo.com On Wednesday, February 5, 2025 at 02:44:37 PM GMT+1, Duncan Murdoch

Re: [R] conditional replacement of elements of matrix with another matrix column

2021-09-01 Thread Mohammad Tanvir Ahamed via R-help
C1 <- A C1[,2][which(B[,1]%in%A[,1])] <- B[,2][which(B[,1]%in%A[,1])] Regards. Tanvir Ahamed On Wednesday, 1 September 2021, 11:00:16 pm GMT+2, Eliza Botto wrote: deaR useRs, I have the matrix "A" and matrix "B" and I want the matrix "C". Is there a way of doing it?

Re: [R] how to get a numeric vector?

2020-10-05 Thread Mohammad Tanvir Ahamed via R-help
Hi,  You can try this.  Example: 1 a <- c(1, 4) b <- c(5, 8) unlist(as.vector(mapply(seq,a,b))) > [1]  1 2 3 4 5 4 5 6 7 8 a <- c(1, 4, 2) b <- c(5, 8, 10) unlist(as.vector(mapply(seq,a,b))) >  [1]  1  2  3  4  5  4  5  6  7  8  2  3  4  5  6  7  8  9 10 Regards. Tanvir Ahamed Sto

Re: [R] data error problem

2020-10-05 Thread Mohammad Tanvir Ahamed via R-help
Hi, In your data file, the first row does not have an equal number of column like the rest of the row.Check your data file. Specially 1st row.   Regards.Tanvir AhamedStockholm, Sweden | mashra...@yahoo.com On Monday, 5 October 2020, 08:11:48 am GMT+2, Mir Md. Abdus Sal

Re: [R] Suppress horizontal mean line in beanplot()

2018-02-13 Thread Mohammad Tanvir Ahamed via R-help
hi,  Check this  beanplot(count ~ spray, data = InsectSprays, what = c(FALSE, TRUE, TRUE, TRUE)) >From R function help :  what :  a vector of four booleans describing what to plot. In the following order, these booleans stand for the total average line, the beans, the bean average, and the bea

Re: [R] How to label a polygon window (spatstat package)

2018-02-09 Thread Mohammad Tanvir Ahamed via R-help
uot;) On Sat, 10 Feb 2018, 16:22 Mohammad Tanvir Ahamed via R-help, wrote: > Hi,  > I want to label a polygon (circle or polygon) inside. > As for example code  > > library(spatstat) > x <- runif(20) > y <- runif(20) > X <- ppp(x, y, window=disc(0.7)) > plot(

[R] How to label a polygon window (spatstat package)

2018-02-09 Thread Mohammad Tanvir Ahamed via R-help
Hi,  I want to label a polygon (circle or polygon) inside. As for example code  library(spatstat) x <- runif(20) y <- runif(20) X <- ppp(x, y, window=disc(0.7)) plot(X) Now I want to label that circle inside . Can some one please help me ?  Thanks.  Regards. Tanvir Ahamed Stockholm,

Re: [R] something weird has happened....!!!!!!!!!!

2017-12-15 Thread Mohammad Tanvir Ahamed via R-help
Dear Akshay, Where is the problem !!Two data set seems identical  except one of them show 10 column and other showing 11 column on r console .   Regards.Tanvir AhamedStockholm, Sweden | mashra...@yahoo.com On Friday, December 15, 2017, 3:49:03 PM GMT+1, akshay kulkarni

[R] Extract all point in a quadrats by spatstat package

2017-11-28 Thread Mohammad Tanvir Ahamed via R-help
Hi, With the following code i can divides window into quadrats and counts the numbers of points in each quadrat. library(spatstat) X <- runifpoint(50) quadratcount(X) quadratcount(X, 4, 5) quadratcount(X, xbreaks=c(0, 0.3, 1), ybreaks=c(0, 0.4, 0.8, 1)) qX <-  quadratcount(X, 4, 5) plot(X) plot(

[R] Merge by Range in R

2017-09-04 Thread Mohammad Tanvir Ahamed via R-help
Hi,  I have two big data set.  data _1 :  > dim(data_1) [1] 15820 5 > head(data_1)    Chromosome  StartEndFeature GroupA_3 1:       chr1 521369  75 chr1-0001    0.170 2:       chr1 750001  80 chr1-0002   -0.086 3:       chr1 8000

[R] Compare output of Violin plot from ggplot2 and vioplot . Need Explanation

2017-07-24 Thread Mohammad Tanvir Ahamed via R-help
Hi,  I have made violin plot with both ggplot2 and vioplot package with same data.  The results and code are as follows.  ###  Loading data  data.melt <- dget("https://gubox.box.com/shared/static/rirth0eym114afwyjxwe128sjzipzdym.txt";) ###  Violin plot by library

Re: [R] Merge selected list element by name

2017-04-13 Thread Mohammad Tanvir Ahamed via R-help
3 4 5 6 7 8 9 10 11 $b [1] 6 7 8 9 10 Hope this helps, Rui Barradas Em 13-04-2017 15:59, Mohammad Tanvir Ahamed via R-help escreveu: > > Hi, > > I have a list like > > kk<- list (a = 1:5, b = 6:10, c = 4:11) > > > Now i want to merger (Union) the list

[R] Merge selected list element by name

2017-04-13 Thread Mohammad Tanvir Ahamed via R-help
Hi, I have a list like kk<- list (a = 1:5, b = 6:10, c = 4:11) Now i want to merger (Union) the list element "a" and "c" by name . My expected outcome is kk1<- list(a_c = 1:11, b = 6:10) I can do it with several lines of code. But can any one have idea to do efficiently/ quickly on a

[R] Merge list element by name

2017-04-13 Thread Mohammad Tanvir Ahamed via R-help
Hi, I have a list like kk<- list (a = 1:5, b = 6:10, c = 4:11) Now i want to merger (Union) the list element "a" and "c" by name . My expected outcome is kk1<- list(a_c = 1:11, b = 6:10) I can do it with several lines of code. But can any one have idea to do efficiently/ quickly on a big da

[R] Unzip multiple layer of compressed (zip/tar) file

2017-03-24 Thread Mohammad Tanvir Ahamed via R-help
Hi, In a folder , there are multiple compressed (zip+tar) files. Each of compressed file can have multiple layer of compression (compressed file inside the compressed file and so on). Can anyone suggest, is there any way to decompress all the files in a single directory ? Tanvir Ahamed

Re: [R] Override/Insert (Change) a value (default value) inside a function

2017-03-11 Thread Mohammad Tanvir Ahamed via R-help
Sweden | mashra...@yahoo.com - Original Message - From: Franklin Bretschneider To: Mohammad Tanvir Ahamed ; R-help groep Sent: Saturday, 11 March 2017, 22:45 Subject: Re: [R] Override/Insert (Change) a value (default value) inside a function Dear Mohammad Tanvir Ahamed, Re:

[R] Override/Insert (Change) a value (default value) inside a function

2017-03-11 Thread Mohammad Tanvir Ahamed via R-help
Hi!, Lets I have a function form a package. The function is, as an example, myplot <- function(x,y) { plot(x,y) } Now I can use the function according to function's defined argument. x<- sort(runif(200)) y<- 1:200 myplot(x,y) Now I want to input extra argument or override default value o

[R] Convert a list with NULL to a dataframe with NA

2016-10-02 Thread Mohammad Tanvir Ahamed via R-help
Hi, I have a list like below. OB1 <- structure(list(aa0 = NULL, aa1 = structure("23403", .Names = "BB10"), aa2 = structure("54904", .Names = "BB20"), aa3 = structure("22897", .Names = "BB30"), aa4 = structure("3751", .Names = "BB40"), aa5 = NULL, aa6 = structure("3679", .Names = "BB50"),

Re: [R] Get the location of a numeric element in a list

2016-06-28 Thread Mohammad Tanvir Ahamed via R-help
Thanks Martin Morgan. Thats works excellent on a large data . Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com - Original Message - From: Martin Morgan To: Mohammad Tanvir Ahamed ; R-help Mailing List Sent: Tuesday, 28 June 2016, 11:07 Subject: Re: [R] Get the location of a

[R] Get the location of a numeric element in a list

2016-06-28 Thread Mohammad Tanvir Ahamed via R-help
Can any one please help me. I will apply this for a very large list, about 400k vector in a list and vector size is unequal and large Example : Input: a <- c(1,3,6,9,25,100) b<-c(10,7,20,2,25) c<-c(1,7,5,15,25,300,1000) d<-list(a,b,c) Expected outcome : # When looking for 1 in d c(1,3) #

Re: [R] [FORGED] Re: Generate list if sequence form two vector element

2016-06-22 Thread Mohammad Tanvir Ahamed via R-help
t; >>>> Hi Tanvir, >>>> Not at all elegant, but: >>>> >>>> make.seq<-function(x) return(seq(x[1],x[2])) >>>> apply(matrix(c(a,b),ncol=2),1,make.seq) >>> >>> >>> Not sure that this is more "elegant" but it&

[R] Generate list if sequence form two vector element

2016-06-22 Thread Mohammad Tanvir Ahamed via R-help
Hi, I want to do the follow thing Input : a <- c(1,3,6,9) b<-c(10,7,20,2) Expected outcome : d<-list(1:10,3:7,6:20,2:9) Thanks !! Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com __ R-help@r-project.org mailing list -- To UNSUBS

Re: [R] sample within a loop

2016-03-19 Thread Mohammad Tanvir Ahamed via R-help
Hi, you can try df1<-split(df,df$groups) lapply(df1, function(x) { x<-cbind(x,entry=0) sam <- sample(x$plotno,1) x$entry[which(x$plotno==sam)]<-"CONTROL" x$entry[which(!x$plotno==sam)]<-"TEST" x } ) Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com ___

Re: [R] R problem : Error: protect(): protection stack overflow

2016-03-15 Thread Mohammad Tanvir Ahamed via R-help
Thanks . I have informed package maintainer. Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com - Original Message - From: Martin Morgan To: Mohammad Tanvir Ahamed ; R-help Mailing List Sent: Tuesday, 15 March 2016, 13:26 Subject: Re: [R] R problem : Error: protect

Re: [R] List funtion

2016-03-15 Thread Mohammad Tanvir Ahamed via R-help
> v3<-list(rep(list(v1),2),rep(list(v2),3)) > v3 [[1]] [[1]][[1]] [1] 8 4 9 12 [[1]][[2]] [1] 8 4 9 12 [[2]] [[2]][[1]] [1] 7 8 11 [[2]][[2]] [1] 7 8 11 [[2]][[3]] [1] 7 8 11 if you want to track each list category. Tanvir Ahamed Göteborg, Sweden | mashra...@yah

[R] R problem : Error: protect(): protection stack overflow

2016-03-14 Thread Mohammad Tanvir Ahamed via R-help
Hi, i got an error while i am running a big data. Error has explained by the following sample sample ## Load data mdata <- as.matrix(read.table('https://gubox.box.com/shared/static/qh4spcxe2ba5ymzjs0ynh8n8s08af7m0.txt', header = TRUE, check.names = FALSE, sep = '\t')) ## Install and load

Re: [R] Extract every 2 element for a list which are not equal in length

2016-03-07 Thread Mohammad Tanvir Ahamed via R-help
Hi Jorge,  Thanks . Some how i have messed up mu lapply function.Worked upon restart.   Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com From: Jorge I Velez To: Mohammad Tanvir Ahamed Cc: R-help Mailing List Sent: Tuesday, 8 March 2016, 3:04 Subject: Re: [R] Extract

Re: [R] Extract every 2 element for a list which are not equal in length

2016-03-07 Thread Mohammad Tanvir Ahamed via R-help
Hi Jim, Thanks . Some how i have messed up mu lapply function. Worked upon restart. Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com - Original Message - From: Jim Lemon To: Mohammad Tanvir Ahamed Cc: R-help Mailing List Sent: Tuesday, 8 March 2016, 3:00 Subject: Re: [R

[R] Extract every 2 element for a list which are not equal in length

2016-03-07 Thread Mohammad Tanvir Ahamed via R-help
Hi, a <- c(1:5)b <- c(1:3) c <- 1 d <- 5 e <- list(a,b,c,d) # To extract every 1st element lapply(e,"[[",1) ## Out-put [[1]] [1] 1 [[2]] [1] 1 [[3]] [1] 1 [[4]] [1] 5 #To extract every 2nd element (Need help in this case) lapply(e,"[[",2) ## Expected outcome [[1]] [1] 2 [[2]]

Re: [R] Extract row form a dataframe by row names in another vector and factor . Need explanation

2016-03-03 Thread Mohammad Tanvir Ahamed via R-help
1:10] colnames(dat2) <- paste0("SA", 1:5) dat2[dat1[, "BB"], ] # desired result Hint: You might want to spend some time to carefully learn the different major data types in R and the various modes of indexing. In general, it is not a good default practice to convert matrices

[R] Extract row form a dataframe by row names in another vector and factor . Need explanation

2016-03-02 Thread Mohammad Tanvir Ahamed via R-help
Hi,Here i have written an example to explain my problem ## Data Generationdat<-data.frame(matrix(1:50,ncol=5)) rownames(dat)<-letters[1:10] colnames(dat)<- c("SA1","SA2","SA3","SA4","SA5") dat1<-data.frame(matrix(letters[1:20],ncol=4)) colnames(dat1)<-c("AA","BB","CC","DD") ## Row names v1<-dat1[

[R] Get object name inside lapply

2016-02-25 Thread Mohammad Tanvir Ahamed via R-help
Hello, I want to get object name of a list inside lapply > c<-list(a=seq(1:5),b=seq(10:20)) > lapply(c,names) $a NULL $b NULL Why NULL ? but i am expecting the names of object . Any help will be appreciated . I want to grab the names of object inside lapply for further process. Th

[R] Get object name inside lapply

2016-02-25 Thread Mohammad Tanvir Ahamed via R-help
Hello,  I want to get object name of a list inside lapply > c<-list(a=seq(1:5),b=seq(10:20))> lapply(c,names)$aNULL $bNULL Why NULL ?  but i am expecting the names of object . Any help will be appreciated .  I want to grab the names of object inside lapply for further process.  Thanks .   Tanvir A

[R] Read a file on every 0.5 (or less) second intervall

2015-11-06 Thread Mohammad Tanvir Ahamed via R-help
Hi, i want to read a file on every 0.5 (or less) second. How can i set this time loop to read a file ? Any idea will be appreciated . Thanks .  Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com [[alternative HTML version deleted]] __

[R] Progress bar in random forest model

2015-09-23 Thread Mohammad Tanvir Ahamed via R-help
Hi , I am using randomForest model in R . For large number of tree my program takes long time to complete . In "randomForest" function i can use "do.trace=TRUE" to see the real time progress . Sample out put in real time on R console is as follows ntree OOB 1 2 3 4

[R] Help with Package creation

2015-09-18 Thread Mohammad Tanvir Ahamed via R-help
Hello , I am new in R package built.  I want to install one package (randomForest) that will install automatically while my package(myPack) will install. I am using R studio to built.  My Description file is :  Package: myPackType: PackageTitle: What the Package Does (Title Case)Version: 0.1Date:

[R] Combine list element by column name to make a dataframe

2015-04-06 Thread Mohammad Tanvir Ahamed via R-help
Hi ,� I have a example list like follow� lst<-list(setNames(c(1,10,50,60,70,80),c("id","id1","math","phy","che","bio")),setNames(c(2,20,45),c("id","id1","phy")),setNames(c(3,30,75),c("id","id1","bio"))) My expected outcome :� -

[R] Merge List element by name

2015-03-07 Thread Mohammad Tanvir Ahamed via R-help
Hi, I have a list like below :  > gg [[1]]       assembly1 GCA_000257985 [[2]]       assembly1 GCA_17125 [[3]]       assembly1 GCA_16805 [[4]]       assembly1 GCA_000144955 [[5]]       assembly                    isolation.source1 GCA_000507725          missing [[6]]       assembly    

Re: [R] Format Sys.time()

2014-01-15 Thread Mohammad Tanvir Ahamed
HI !! try it  format(Sys.time(), "%Y_%m_%d_%X")   Best regards ...  Tanvir Ahamed Göteborg, Sweden From: "Yuan, Rebecca" To: R help Sent: Wednesday, 15 January 2014, 15:56 Subject: [R] Format Sys.time() Hello all, I know that th

Re: [R] How to get a substring from a string

2014-01-15 Thread Mohammad Tanvir Ahamed
Hi ! Try it  st<-'yab~a+b+c' strsplit(st,"~")[[1]][1]    Best regards ...  Tanvir Ahamed Göteborg, Sweden From: "Yuan, Rebecca" To: R help Sent: Wednesday, 15 January 2014, 15:38 Subject: [R] How to get a substring from a string

[R] Replace value in a matrix according to a list with a list of value .

2014-01-09 Thread Mohammad Tanvir Ahamed
Hi there !! I have a matrix like  > mm       [,1] [,2] [,3]  [1,]    1   11   21  [2,]    2   12   22  [3,]    3   13   23 I have a list of position index like  > pos $row1 [1] 1 3 $row2 [1] 3 2 $row3 [1] 1 3 2 I have a list of values like > gty $v1  9  3  $v2  4  8  $v3  7  4  1   

Re: [R] Select rows of a data frame according to values of vector in a list

2014-01-03 Thread Mohammad Tanvir Ahamed
llo, Try the following. lapply(lis, function(i) df[i, ]) Hope this helps, Rui Barradas Em 03-01-2014 09:04, Mohammad Tanvir Ahamed escreveu: > Hi there !! > > I have a list like as follows : >> lis > $lis1 > [1] 1 3 5 > > $lis2 > [1] 2 4 6 8 9 > > I have anoth

[R] Select rows of a data frame according to values of vector in a list

2014-01-03 Thread Mohammad Tanvir Ahamed
Hi there !! I have a list like as follows :  >lis $lis1 [1] 1 3 5  $lis2 [1] 2 4 6 8 9 I have another data frame like as follows  >df 1 10 110 2 15 120 3 20 130 4 25 140 5 30 150 6 35 160 7 40 150 8 45 180 9 50 190 Now i want to select the rows of data frame by the value of list and the output

Re: [R] Apply a function with multiple argument on each column of matrix

2013-11-11 Thread Mohammad Tanvir Ahamed
Thanks !!   Best regards ...  Tanvir Ahamed Göteborg, Sweden On Monday, 11 November 2013, 13:49, Uwe Ligges wrote: On 11.11.2013 13:31, Mohammad Tanvir Ahamed wrote: > Hi there !! > I have a function like > fun <- function(x,y) > { > loe<

[R] Apply a function with multiple argument on each column of matrix

2013-11-11 Thread Mohammad Tanvir Ahamed
Hi there !! I have a function like  fun <- function(x,y)  { loe<-loess(y ~ x,span=0.9,family="gaussian") pre<-predict(loe,data.frame(x=x)) return(pre) } Now i have defined :  x<-1:500 y<-matrix(rnorm(1000,3),ncol=2) I can manipulate fun(x,y[,1]) . But i want to apply the function on each column

[R] Problem with biomaRt::getSequence.

2013-05-07 Thread Mohammad Tanvir Ahamed
Hi, I can run the code some days ago . But cant run now.  Problem 1: Output is ok ensembl = useDataset("hsapiens_gene_ensembl",mart=ensembl) utr5 = getSequence(chromosome=3, start=185514033, end=185535839,  type="entrezgene",seqType="5utr", mart=ensembl)  Output :                                 

[R] Conflict command getSequence {biomaRt} and getSequence {seqinr} !!

2013-02-07 Thread Mohammad Tanvir Ahamed
Hi !  Facing problem with " getSequence" commend .  when only biomaRt package loaded the following example working well  >mart <- useMart("ensembl",dataset="hsapiens_gene_ensembl") >seq = getSequence(id="BRCA1", type="hgnc_symbol", seqType="peptide", mart = >mart) show(seq) but when i have lo

[R] Reorder a data frame according a column randomly reordered.

2011-04-18 Thread Mohammad Tanvir Ahamed
Hello all ,  I have a data frame like this  X1X2X3 11815 22916 331017 441118 551219 661320 771421 now i want to randomly reorder the variable X2  but the row element should be same  as for example  X1X2X3 12916 251219 331017 471421 561320 61815 741118 how can i do that ?? Hint :  this could b

[R] if (cond) expr1 expr2 ??

2011-04-13 Thread Mohammad Tanvir Ahamed
hi , this can be done easily if (cond) expr ex:  > for (i in 1: 4)+ {+ if(i==2) print("a")+ if(i==2) print("b")+ } output : [1] "a"[1] "b" but i want this  if (cond) expr1 expr 2 i tried this :  > for (i in 1: 4)+ {+ if(i==2) (print("b") && print("a"))+ } output : [1] "b"Error in print("b") && prin