[Solved] Multiple aggregation in R with 4 parameters

You could try something like this in data.table data <- data.table(yourdataframe) bar <- data[,.N,by=y] foo <- data[x==1 & z==1,list(mean.t=mean(t,na.rm=T),median.t=median(t,na.rm=T)),by=y] merge(bar[,list(y)],foo,by=”y”,all.x=T) y mean.t median.t 1: 1 12.5 12.5 2: 2 NA NA 3: 3 NA NA 4: 4 NA NA You probably could do the same in aggregate, but I am not sure you can do … Read more

[Solved] Combining csv files in R to different columns [closed]

Here’s an option. It’s more or less handcrafted as I’m not aware of any single command to do this exactly as you’ve specified. # the working directory contains d1.csv, d2.csv, d3.csv with # matching first two columns. The third column is random data read.csv(“./d1.csv”) #> a b c #> 1 1 A 0.5526777 #> 2 … Read more

[Solved] ploting ggmap with geom Points (lat_long) annotated 1 to19. Points data is in CSVfile

Here is one approach. I created new lat for text annotation using transform in base R. I used geom_text to add the labels you wanted. I used scale_colour_discrete to change the name of the legend. library(ggmap) library(ggplot2) ### Get a map map <- get_map(location=c(lon=34.832, lat=0.852), color=”color”, source=”google”, maptype=”terrain”, zoom=9) ### Create new lat for annotation … Read more

[Solved] need to find a pattern and extract that out [closed]

I’ll take one stab at this with two implementations. First, I’ll use a character vector. If yours is in a frame, replace it with myframe$mycolumn. v <- c(“110231 validation 108871 validation 85933”, “21102 validation 93442 21232 validation 73769 26402 validation 127221 26402”, “99763 99763 validation 99763 validation 99763”, “validation 199022 validation 122099 validation 12209 validation … Read more

[Solved] Converting a year-month column to date type [duplicate]

You can use paste to paste the day with the ‘Date’ column, convert to Date class using as.Date with the appropriate format argument. df1$Date <- as.Date(paste(df1$Date, ’01’), ‘%Y %B %d’) For more info, you can check ?as.Date, ?strptime, ?as.POSIXct 1 solved Converting a year-month column to date type [duplicate]

[Solved] Finding the index based on two data frames of strings

A possible solution with base R by using a combination of colSums, which, toString and apply: strs$colids <- apply(strs, 1, function(x) toString(which(colSums(lut == x, na.rm=TRUE) > 0))) which gives: > strs strings colids 1 O75663 1, 3 2 O95400 1, 3 3 O95433 1, 3 4 O95456 2, 3, 4 5 O95670 2, 3, 4 … Read more

[Solved] Subset all rows by group by type

I would use indexing # save all the “transactions” where iteamtype equals “a” to an object called F f <- df[ df$itemType %in% “a” , “transaction” ] #optional (look as f) print(f) print( unique(f)) # Subset to all the rows which equals one of the “transactions” stored in the object f df[ df$transaction %in% unique( … Read more

[Solved] Creating a matrix with random generated variables in R [closed]

Is this what you want? mat <- as.matrix(data.frame(V1 = sample(1:2, 100, replace = TRUE), V2 = sample(1:5, 100, replace = TRUE), V3 = sample(10:50, 100, replace = TRUE), V4 = sample(1:3, 100, replace = TRUE), V5 = sample(1:5, 100, replace = TRUE))) 1 solved Creating a matrix with random generated variables in R [closed]

[Solved] How to calculate a condition using dplyr?

As I understand it, you want a column that checks if the temperature deviates by 5 – 6 degrees (if the temp is greater than 10) and another column to check if it is differs by 7 degrees or more. The current code you are using seems to identify the coldwave values correctly, although is … Read more