Posts

Showing posts with the label r

Getting repeated results in SVM in R

Getting repeated results in SVM in R I'm trying to predict using SVM from R package "e1071". But I'm getting repeated values as predicted outcomes. I have run this several times but getting same results. Please help me to find what wrong is going here. library(e1071) tuneResult <- tune(svm,y~.,data=calibration.data,ranges = list(epsilon = seq(0,1,0.1), cost = 2^(2:9))) tunedModel <- tuneResult$best.model predict.data<-predict(tunedModel,prediction.data) predict.data 2006-03-01 2006-04-01 2006-05-01 2006-06-01 2006-07-01 2006-08-01 2006-09-01 2006-10-01 2006-11-01 2006-12-01 2007-01-01 2007-02-01 2007-03-01 2007-04-01 2007-05-01 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 0.05798676 2007-06-01 2007-07-01 2007-08-01 2007-09-01 2007-10-01 2007-11-01 2007-12-01 2008-01-01 2008-02-01 2008-03-01 2008-04-01 2008-05-01 2008-06-01 2008-07-01 2008-08-01 0.05798...

R Extract values from data frame with vectors

Image
R Extract values from data frame with vectors I hope my question is not a duplicate, but I really couldn't find what I need. I dived in dplyr and even did the data.table course from DataCamp, but I can't fix it. Maybe overlooking something? I have this df: set.seed(1964) df<-data.frame(id = c( "XEY", "NZH", "DYE", "JNF", "LHH", "WNB"), q_1 = sample(5,6, replace = TRUE), q_2 = sample(5,6, replace = TRUE), q_3 = sample(5,6, replace = TRUE), q_4 = sample(5,6, replace = TRUE), q_5 = sample(5,6, replace = TRUE)) So my df looks like this: Next I have two vectors with id's (row-indicators) and q's (question numbers) like these: id <- c("XEY", "DYE", "JNF", "DYE", "XEY", "LHH", "WNB", "JNF" ) question <- c("val_1", "val_1","val_3","val_3"...

Error when trying to fit a STERGM model in statnet R

Error when trying to fit a STERGM model in statnet R I'm trying to analyze my data using STERGM (part of package statnet) but I'm experiencing some errors I can't figure out whenever I add node covariate terms to the formula's parameters. This is the error I get immediately after running the code: STERGM *Error in ergm.getglobalstats(nw, m, response = response) : NA/NaN/Inf in foreign function call (arg 13)* My networkDynamic object consists of 5 networks, with changing active vertices. Googling around (and some basic intuition) tells me I have some missing ( NA/NaN ) vertex attributes, but after double and triple checking this isn't the case. I tried different quantitative attributes (one with permanent values over all networks, another with varying values in each network) but all produce the same error. When fitting each of the 5 networks separately using a "simple" ERGM with the same node covariate terms, everything works fine. networkDynamic NA/NaN ...

How to extract rows from my data frame without having a data format conversion?

How to extract rows from my data frame without having a data format conversion? I would like to extract rows from a big dataset, named data1. My destination is to add a new column next to the Value of the extracted data1. Before that, I need to extract some GeneSymbols and then I would like to make a new column in the extracted data frame. Let's hypothetically say if this is my data. GeneSymbol ID Value let-7 A 0.5 miR-16 A 0.7 miR-19 A 0.3 miR-21 A 0.2 add1 = 1 data11 = cbind(data1, add1) head(data11) GeneSymbol ID Value add1 let-7 A 0.5 1 miR-16 A 0.7 1 miR-19 A 0.3 1 miR-21 A 0.2 1 It works well if I do not extract rows from my data set. However, I am in trouble if I do like this. newdata1 = data1[c("let-7", "miR-19"),] head(newdata1) GeneSymbol ID Value <NA> <NA> NA <NA> <NA> NA Why my data became NAs? I got stuck. Since my real data is big, over 30,000 rows. Also, my target ...

What is a good tool for testing R packages when a new commit happens in Git? [closed]

What is a good tool for testing R packages when a new commit happens in Git? [closed] I am looking for something similar to Jenkins which can test a R package when a new commit or pull requested in Git against a standard test data set. This question appears to be off-topic. The users who voted to close gave this specific reason: 1 Answer 1 I use travis to control my package: (same as devtools::check) and codecov to check my code coverage. To sse how I set them up, you can check my package dataPreparation and look into my .travis.yml Wonderful! thanks a lot.! – pyBug Jul 2 at 15:02 If i solved your problem, consider giving a +1 and validate the answer – Emmanuel-Lin Jul 2 at 18:26 ...

`bookdown`/`rmarkdown`/`knitr`: Hook for execution after output document is finalized?

`bookdown`/`rmarkdown`/`knitr`: Hook for execution after output document is finalized? My PDF -report generation using bookdown includes packing of result files into a zip archive, into which I (currently manually) integrate the PDF document itself as well. PDF bookdown zip PDF Is there any hook that would enable automating the integration of the finished PDF ? WOuld require a post- pdflatex command by knitr , I suppose ... PDF pdflatex knitr How do you currently trigger the knitting? The RStudio button? Is something along the lines of this stackoverflow.com/questions/39713618/… helpful? – CL. Jul 2 at 12:27 That looks interesting indeed ... off investigating. – balin Jul 2 at 15:33 ...

Output in Julia Escher.jl in web very plain

Output in Julia Escher.jl in web very plain So, I have this code r.jl and I am fully newbie to this and this is only a school projects, yes it suppose to be easy using shiny in r, but my professor doesn't want something simple: r.jl using RCall using ImageView, Images R"library(NLP)" R"library(RColorBrewer)" R"library(tm)" R"library(SnowballC)" R"library(e1071)" R"library(gplots)" R"library(ROCR)" R"library(gmodels)" R"library(caret)" R"library(xtable)" R"sms_raw <- read.csv('/home/r/sms_spam.csv', stringsAsFactors = FALSE)" R"str(sms_raw)" R"summary(sms_raw)" R"sms_raw$type <- factor(sms_raw$type)" R"sms_results <- read.csv('/home/r/sms_results.csv')" R"confusionMatrix(sms_results$predict_type, sms_results$actual_type, positive = 'spam')" R"pred <- prediction(predictions = sms_resul...

Error in running randomForest : object not found

Error in running randomForest : object not found So i am trying to fit a random forest classifier for my dataset. I am very new to R and i imagine this is a simple formatting issue. I read in a text file and transform my dataset so it is of this format: (taking out confidential info) >head(df.train,2) GOLGA8A ITPR3 GPR174 SNORA63 GIMAP8 LEF1 PDE4B LOC100507043 TGFB1I1 SPINT1 Sample1 3.726046 3.4013711 3.794364 4.265287 -1.514573 7.725775 2.162616 -1.514573 -1.5145732 -1.514573 Sample2 4.262779 0.9261892 4.744096 7.276971 -1.514573 4.694769 4.707387 2.031476 -0.8325444 2.615991 ... ... CD8B FECH PYCR1 MGC12916 KCNA3 resp Sample1 -1.514573 2.099336 3.427928 1.542951 -1.514573 1 Sample2 -1.145806 1.204241 2.846832 1.523808 1.616791 1 In essence the columns are my features and the rows my samples, the last column is my response vector which is a column of factors, resp. Then i use: set.seed(1) #Set the seed in order to gain reproduci...

grouping synonyms in R

grouping synonyms in R I am a beginner I want to find synonyms in sentences and group them together and replace only one of the synonyms in the sentences. I used the above code and I could find synonyms and the number of repetitions of words. But I can not group them together and replace one of them. Does anyone have a sample code? Thank you so much if you help me. With respect what have you tried so far? – Melissa Key Jul 2 at 5:30 We cant see the code. Add it – Resham Wadhwa Jul 2 at 5:48 When you add the code, could you also explain what you mean by "group them together", and "replace one of them"? It's not clear exactly what you're try...

Error in XLConnect

Error in XLConnect I am trying to import an excel sheet into r. I used the following code: x <- loadWorkbook("x.xlsx") b <- readWorksheet(x, sheet="b") The first line works fine, however, running the second gives the following error: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘readWorksheet’ for signature ‘"jobjRef", "character"’ I have no missing values in that sheet. For the purpose of reproducing, download trial.xlsx from https://github.com/ahmedfsalhin/1stpaper. trial.xlsx system info: Yosemite operating system. It would be very helpful to post a link to an example workbook that causes this. That said, Yosemite is brand-new; you may need to reinstall Java and/or wait for new CRAN builds of Rjava . – Carl Witthoft Oct 27 '14 at 14:07 ...

Z score normalizing r dataframe consecutively

Z score normalizing r dataframe consecutively I would like to normalize an R data.frame by computing the z-score using the function scale() . data.frame scale() However, I am not sure whether this approach is subject to "look-ahead bias", which is a finance term for making up features that would not have been known or available during the period being analyzed. These are stock returns, and I want to use this data for a "backtest" (a finance term for validation). I want to make sure that each period's z-score is only using data available up to that point and not the entire series mean and std when computing the z-score. Does anyone know how to perform the calculation for this? Or is there a different approach? Could you provide a sample of your data using reprex::reprex() or dput() . It sounds like you don't want want to standardize columns all at once using all the data, but rather standardize them in periods or chunks. Is this ...

How do you specifically order ggplot2 x axis instead of alphabetical order?

Image
How do you specifically order ggplot2 x axis instead of alphabetical order? I'm trying to make a heatmap using ggplot2 using the geom_tiles function here is my code below: heatmap ggplot2 geom_tiles p<-ggplot(data,aes(Treatment,organisms))+geom_tile(aes(fill=S))+ scale_fill_gradient(low = "black",high = "red") + scale_x_discrete(expand = c(0, 0)) + scale_y_discrete(expand = c(0, 0)) + theme(legend.position = "right", axis.ticks = element_blank(), axis.text.x = element_text(size = base_size, angle = 90, hjust = 0, colour = "black"), axis.text.y = element_text(size = base_size, hjust = 1, colour = "black")). data is my data.csv file my X axis is types of Treatment my Y axis is types of organisms I'm not too familiar with commands and programming and I'm relatively new at this. I just want to be able to specify the order of the labels on the x axis. In this case, I'm trying to specify the order of...

Converting between long and short data.frame formats

Converting between long and short data.frame formats Simple (?) tidyr question: tidyr I have a data.frame which has several grouping columns and several value columns, in long format. I want to convert it to short (wide) format, where the key would be one of the grouping columns and the resulting data.frame would have a column for each combination of all the other grouping columns and each of the value columns. data.frame key data.frame Here's my long-format data.frame : data.frame set.seed(1) library(dplyr) df <- data.frame(treatment = rep(c(rep("T1",3),rep("T2",3)),2), species = c(rep("S1",6),rep("S2",6)), group = rep(LETTERS[1:3],4), n = as.integer(runif(12,10,20))) %>% dplyr::group_by(treatment,species) %>% dplyr::mutate(freq = n/sum(n)) And here's what I want the resulting wide-format data.frame to be: data.frame res.df <- data.frame(group = LETTERS[1:3], ...

How do I get csv + json data in tabular form in R language

How do I get csv + json data in tabular form in R language id,event,event_timestamp,properties 43e172a91,Cart is viewed,2016-08-19 02:07:56.88,"{""email_id"": ""chem@gmail.com"", ""timeStamp"": ""29-08-2016 07:43:10"", ""No Of Products"": 1, ""Cart Value"": ""1495""}" By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

when use xyplot and abline, error: plot.new has not been called yet

when use xyplot and abline, error: plot.new has not been called yet theta<-seq(90,110,0.01) xyplot(F1(theta)~theta,type="l", col = rgb(red = 255, green = 90, blue = 0, maxColorValue = 255), cex.lab = 3.5, cex.axis = 3.5, lwd=2 ) abline(a=NULL, b=NULL, h=NULL, v=100) F1 is defined as a whatever function, and I got Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet you are mixing base r plotting and lattice . see stackoverflow.com/questions/11949766/… for abline in lattice – user20650 Jul 1 at 22:54 By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Shiny app: No error reported, but why the VAR6A_2 is empty?

Shiny app: No error reported, but why the VAR6A_2 is empty? Hey I have a question with shiny. After I click on 'Run App", no error is reported, but the tabpanel VAR 6A_2 is empty.. I tried the code outside the app, the code works. But after I move the code inside the app, no result is showed. So confusing. Another question is, I need to create more than 30 tabpanels for the app. Each tabpanle has one variable. What makes thing complicated is, for some of the variables, they are computed with their above variables. For example, Var 4 is computed from Var 2 and Var 3. Here I store all the variables in one app. It is a little confusing because there are so many variables. Is there a better way to organize them? Thanks a lot. Here is the code, thanks. library(shiny) library(plotly) #library(d3heatmap) library(dplyr) #library(ggplot2) #library(ggthemes) #library(gplots) library(readxl) library(tidyr) #source('./utils.R') Index_2 <- read_xlsx('Index 2.xlsx') Index...

R Flexdashboard multiple plots on single tab

R Flexdashboard multiple plots on single tab I'm trying to put multiple dygraph plots on a single tab of a flexdashboard. I've tried a bunch of different options from here and from here My RMD file looks like this: --- title: "Project Dashboard" output: flexdashboard::flex_dashboard: orientation: columns vertical_layout: scroll --- # Intro {.sidebar} # Page 1 ## Column 1 {.tabset .tabset-fade data-width=850} ### Site 1 ```{r Data, echo=FALSE, fig.height=2} s <- dygraph(as.xts(df,order.by=df$DateTime), group = "NC") %>% dyOptions(drawPoints = TRUE, pointSize = 1) %>% dyAxis("y", label = "Salinity (PSU)", valueRange = c(16, 30)) %>% dyRangeSelector(height = 20) %>% dyLegend(width = 400) t <- dygraph(as.xts(df,order.by=df$DateTime), group = "NC") %>% dyOptions(drawPoints ...

Creating an array with data conditional on another matrix

Creating an array with data conditional on another matrix I know there must be an apply function or ave for this, but I am not quite sure how to do it: I have data: date player market 1: 1-1 1 1 2: 1-1 2 1 3: 1-1 1 2 4: 1-2 2 1 5: 1-2 3 2 6: 1-3 21 1 7: 1-4 1 1 8: 1-4 51 1 9: 1-4 1 1 10: 1-5 1 2 I also have a blank array, which has unique dates on the rows, unique markets on the columns, and unique players for the third dimension. 1 [,,1] 1 2 1-1 1-2 1-3 1-4 1-5 2 [,,2] 1 2 1-1 1-2 1-3 1-4 1-5 etc I want to fill out the array with from the data. I want each point to = 1 if the guy has an entry in the data where he is present for a date and market combination, and 0 if not. So for example, for 1 and 2, they would be filled out as: 1 [,,1] 1 2 1-1 1 1 1-2 0 0 1-3 0 0 1-4 0 1 1-5 0 1 2 [,,2] 1 2 1-1 1 0 1-2 1 ...

select only rows with duplicate id and specific value from another column in R

select only rows with duplicate id and specific value from another column in R I have the following data with ID and value: id <- c("1103-5","1103-5","1104-2","1104-2","1104-4","1104-4","1106-2","1106-2","1106-3","1106-3","2294-1","2294-1","2294-2","2294-2","2294-2","2294-3","2294-3","2294-3","2294-4","2294-4","2294-5","2294-5","2294-5","2300-1","2300-1","2300-2","2300-2","2300-4","2300-4","2321-1","2321-1","2321-2","2321-2","2321-3","2321-3","2321-4","2321-4","2347-1","2347-1","2347-2","2347-2") value <- c(6,3,6,3,6,3,6,3,6,3,3,6,9,3,6,9,3,6,3,6,9,3,6,9,6,9,6,9,6,9,3,9,3,9,3,9...