data-manipulation
R: x ‘probs’ outside [0,1]
The x values generated are random and they can be positive or negative. probs argument of quantile needs to have values between 0 and 1. One way would be to take the absolute value of x[5:7] and turn them to ratio using prop.table. x[5:7] <- prop.table(abs(x[5:7])) Complete function – library(optimization) fitness <- function(x) { #bin … Read more
jQuery jqGrid Show message when an edit row is complete
First of all the option closeAfterEdit:true follows to closing of the edit form after the successful server response. You should change the setting to the default value closeAfterEdit:false to be able to show anything. Next I would recommend you to use navigator toolbar instead of creating a button after outside of the grid. In the … Read more
Read a CSV from github into R
Try this: library(RCurl) x <- getURL(“https://raw.github.com/aronlindberg/latent_growth_classes/master/LGC_data.csv”) y <- read.csv(text = x) You have two problems: You’re not linking to the “raw” text file, but Github’s display version (visit the URL for https:\raw.github.com….csv to see the difference between the raw version and the display version). https is a problem for R in many cases, so you … Read more
Shifting non-NA cells to the left
You can use the standard apply function: df=data.frame(x=c(“l”,”m”,NA,NA,”p”),y=c(NA,”b”,”c”,NA,NA),z=c(“u”,NA,”w”,”x”,”y”)) df2 = as.data.frame(t(apply(df,1, function(x) { return(c(x[!is.na(x)],x[is.na(x)]) )} ))) colnames(df2) = colnames(df) > df x y z 1 l <NA> u 2 m b <NA> 3 <NA> c w 4 <NA> <NA> x 5 p <NA> y > df2 x y z 1 l u <NA> 2 m … Read more
How do I remove objects from an array in Java?
An alternative in Java 8: String[] filteredArray = Arrays.stream(array) .filter(e -> !e.equals(foo)).toArray(String[]::new);
Split delimited strings in a column and insert as new rows [duplicate]
As of Dec 2014, this can be done using the unnest function from Hadley Wickham’s tidyr package (see release notes http://blog.rstudio.org/2014/12/08/tidyr-0-2-0/) > library(tidyr) > library(dplyr) > mydf V1 V2 2 1 a,b,c 3 2 a,c 4 3 b,d 5 4 e,f 6 . . > mydf %>% mutate(V2 = strsplit(as.character(V2), “,”)) %>% unnest(V2) V1 V2 … Read more
How can I access and process nested objects, arrays or JSON?
Preliminaries JavaScript has only one data type which can contain multiple values: Object. An Array is a special form of object. (Plain) Objects have the form {key: value, key: value, …} Arrays have the form [value, value, …] Both arrays and objects expose a key -> value structure. Keys in an array must be numeric, … Read more