Converting String Array to an Integer Array

You could read the entire input line from scanner, then split the line by , then you have a String[], parse each number into int[] with index one to one matching…(assuming valid input and no NumberFormatExceptions) like String line = scanner.nextLine(); String[] numberStrs = line.split(“,”); int[] numbers = new int[numberStrs.length]; for(int i = 0;i < … 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?

[If you want some ready-to-use code, please scroll to my “Edit3” (after the cut). The rest is here for posterity.] To flesh out Dustman’s idea: List<String> list = new ArrayList<String>(Arrays.asList(array)); list.removeAll(Arrays.asList(“a”)); array = list.toArray(array); Edit: I’m now using Arrays.asList instead of Collections.singleton: singleton is limited to one entry, whereas the asList approach allows you to … Read more

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