[Solved] How to create multiple data frames from a huge data frame using a loop? [closed]

given that your data frame is named veryVeryVERYLargeDF lapply(colnames(veryVeryVERYLargeDF)[2:ncol(veryVeryVERYLargeDF)], function(nameOFColumnInveryVeryVERYLargeDF) cbind(veryVeryVERYLargeDF$ID, veryVeryVERYLargeDF[,nameOFColumnInveryVeryVERYLargeDF])) that will give you a list of somewhatSmallerDFs, where each somewhatSmallerDF is simply the ID column from veryVeryVERYLargeDF and one of the other columns from veryVeryVERYLargeDF 2 solved How to create multiple data frames from a huge data frame using a loop? [closed]

[Solved] R script : add a padding to the ymax of the plot with ggplot2

No code to generate your sample data was provided, so I used the code @akrun had used previously: y3 <- matrix(rnorm(5000), ncol = 5) library(tidyverse) as.data.frame(y3) %>% mutate(row = row_number()) %>% # add row to simplify next step pivot_longer(-row) %>% # reshape long ggplot(aes(value, color = name)) + # map x to value, color to … Read more

[Solved] Bubble plot of mine quakes [closed]

Edit: Updated to use more meaningful data. The original response is at the bottom. This map… … can be produced with the following code: library(ggplot2) library(maptools) # grab earthquake data [source: USGS Earthquake Hazards Program] url <- “http://comcat.cr.usgs.gov/fdsnws/event/1/query” querystring <- “starttime=2012-01-01T00:00:00Z” querystring <- paste(querystring,”minmagnitude=6″, sep=”&”) # magnitude >= 6 querystring <- paste(querystring,”mindepth=0″, sep=”&”) querystring <- … Read more

[Solved] Is QwtRasterData the right Qt device for displaying the data received from get_googlemap?

QwtRasterData is an abstract class that defines an interface to gridded data for display in the Qwt framework. There exists a subclass, QwtMatrixRasterData that lets you create raster objects with actual values in them from a QVector of doubles using the setValueMatrix method. You could write another subclass QwtRdaRasterData that defines the methods of the … Read more

[Solved] what is the result of 4*0:g_range[2]? [closed]

0:n returns the vector c(0, 1, 2, …, n) and 4*0:n will multiply each element by 4 to yield c(0, 4, 8, …, 4n). So, this gives a vector in which the difference between each element is 4. It does not give a vector of four equally spaced elements except in the case that n … Read more

[Solved] Extract components of strings and fill-down where missing in R

Based on the discussion in the comments it appears that it is not feasible to construct a key for joining the Species_name with a look-up table. What you could do is determine the “similarity” of your (species) names with such a look-up table. This assumes that your (species) names are different enough. To determine the … Read more

[Solved] In R, how to turn characters (grades) into a number and put in a separate column

Often you can use a named vector to do these sorts of mapping operations simply: students <- data.frame(name=c(“J. Holly”,”H. Kally”, “P. Spertson”, “A. Hikh”, “R. Wizht”), CRSE_GRADE_OFF=c(“A”,”D”,”E”,”A”,”A”)) scores = c(A=1, B=2, C=3, D=4, E=5, F=6) students$grade <- scores[as.character(students$CRSE_GRADE_OFF)] students # name CRSE_GRADE_OFF grade # 1 J. Holly A 1 # 2 H. Kally D 4 … Read more

[Solved] Dataframe with string columns – each column need to split into multiple at word “and” – R [closed]

Here is what worked for me – using inputs from above and various other threads on SO. I am a complete newbie to R and my objective is to migrate work from excel to R. # returns string w/o leading or trailing whitespace trim <- function (x) gsub(“^\\s+|\\s+$”, “”, x) #——————————————————————————– # OBJECTIVE – migrate … Read more

[Solved] Convert categorical column to multiple binary columns [duplicate]

One way could be using unique with a for-loop Breed = c( “Sheetland Sheepdog Mix”, “Pit Bull Mix”, “Lhasa Aposo/Miniature”, “Cairn Terrier/Chihuahua Mix”, “American Pitbull”, “Cairn Terrier”, “Pit Bull Mix” ) df=data.frame(Breed) for (i in unique(df$breed)){ df[,paste0(i)]=ifelse(df$Breed==i,1,0) } solved Convert categorical column to multiple binary columns [duplicate]

[Solved] assign value to a variable rather than using if statement

This is a merge operation as far as I can tell. Make a little lookup table with your Gbcode/ncnty data, and then merge it in. # lookup table lkup <- data.frame(Gbcode=c(11,12,13),ncnty=c(20,19,198)) #example data dt <- data.frame(Gbcode=c(11,13,12,11,13,12,12)) dt # Gbcode #1 11 #2 13 #3 12 #4 11 #5 13 #6 12 #7 12 Merge: merge(dt, … Read more

[Solved] How to make a stacked plot in R [duplicate]

There are many (many!) online resources explaining how to create a stacked barplot in R. Without more details, such as the code you’ve tried and/or what error messages you are getting, we can only guess at potential solutions. E.g. do either of these approaches help? Or do you want your plot to look different? DA … Read more

[Solved] counting the number of people in the system in R

If I understand your question, here’s an example with fake data: library(tidyverse) library(lubridate) # Fake data set.seed(2) dat = data.frame(id=1:1000, type=rep(c(“A”,”B”), 500), arrival=as.POSIXct(“2013-08-21 05:00:00”) + sample(-10000:10000, 1000, replace=TRUE)) dat$departure = dat$arrival + sample(100:5000, 1000, replace=TRUE) # Times when we want to check how many people are still present times = seq(round_date(min(dat$arrival), “hour”), ceiling_date(max(dat$departure), “hour”), “30 … Read more

[Solved] Calculations between two columns in a data frame in R

Here is a solution with base R, where ave() and cumsum() are applied to get the expected: For original data df: dfs <- split(df,df$product) df <- Reduce(rbind,lapply(dfs, function(x) { within(x, expected <- ave(const-value, ave(const-value, cumsum(const>value),FUN = cumsum)>0,FUN = cumsum)) })) such that > df product data value const expected 1 A 2020-01-01 10 100 90 … Read more