r

Vlookup and Count String Occurrences in Separate Table R to new Column

…衆ロ難τιáo~ 提交于 2021-02-10 19:53:25
问题 I have two data frames. Below are samples but should be easily reproducible for illustration. df1 <- data.frame(School = c("Omaha South", "Omaha Central", "Grand Island"), Enrollment = c(2166, 2051, 1982)) df2 <- data.frame('Away Score' = c(25, 57, 76), 'Away Team' = c("Omaha South", "Omaha Central", "Grand Island"), 'Away Score' = c(52, 88, 69), 'Away Team' = c("Omaha Central", "Grand Island", "Omaha South"), Date = c("1/11/2020", "1/12/2020", "1/13/2020"), Winner = c("Omaha Central", "Grand

Long to wide format with several duplicates. Circumvent with unique combo of columns

徘徊边缘 提交于 2021-02-10 19:53:24
问题 I have a dataset similar to this (real one is way bigger). It is in long format and I need to change it to wide format with one row per id. My problem is that there are a lot of different combinations of time, drug, unit and admin. Only a combination of time, drug, unit and admin will be unique and should only occur once pr id. I could not find a solution to this. I would like R to create unique combinations of columns so the data can be transformed to wide format. I have tried melt.data

Transform a pairwise set of values into a matrix

旧城冷巷雨未停 提交于 2021-02-10 19:43:18
问题 I would like to transform the following dataframe in R: > df <- data.frame(cbind(rep(c("F1","F2","F3"),3), rep(c("F1","F2","F3"),each=3),c(1,2,3,4,5,6,7,8,9))) into the following matrix: mat <- matrix(c(1,2,3,4,5,6,7,8,9),nrow=3, dimnames=list(c("F1","F2","F3"), c("F1","F2","F3"))) It seems like apply would be a likely candidate but I can't seem to get the syntax correct. Thanks very much 回答1: Try res <- xtabs(as.numeric(as.character(X3))~., df) attr(res, 'class') <- NULL attr(res, 'call') <-

Transform a pairwise set of values into a matrix

戏子无情 提交于 2021-02-10 19:41:57
问题 I would like to transform the following dataframe in R: > df <- data.frame(cbind(rep(c("F1","F2","F3"),3), rep(c("F1","F2","F3"),each=3),c(1,2,3,4,5,6,7,8,9))) into the following matrix: mat <- matrix(c(1,2,3,4,5,6,7,8,9),nrow=3, dimnames=list(c("F1","F2","F3"), c("F1","F2","F3"))) It seems like apply would be a likely candidate but I can't seem to get the syntax correct. Thanks very much 回答1: Try res <- xtabs(as.numeric(as.character(X3))~., df) attr(res, 'class') <- NULL attr(res, 'call') <-

How to add CSS external files to be used by my R package function?

夙愿已清 提交于 2021-02-10 19:40:21
问题 I'm making a personal package and would like to load a css file in one of the functions in this package in order to have a "default style". What is the optimal way of doing this? I cannot find any documnetation that helps me understand how to work with external data like a css file, mostly what I find is about exporting external datasets to be loaded separately, etc. 回答1: I found the problem. I was using the inst/extdata folder to export my style.css file, but was trying to read it directly

Return three lists with foreach loop in R

一曲冷凌霜 提交于 2021-02-10 19:35:42
问题 I've been struggling with the workings of foreach loops in R. To speed up my code I'm trying to change my for loop into a foreach loop with %dopar%. My goal is to end up with three lists of the same length, each filled with data frames that represent scores between two users (I'm comparing three different calculation methods). My code used to be (very basic representation): for (a in 1:5) { #Just creating some sample data resultA <- data.frame(matrix(nrow = 40, ncol = 3)) resultB <- data

Getting error message while calculating rmse in a time series analysis

时间秒杀一切 提交于 2021-02-10 19:35:20
问题 I am trying to replicate this example of time series analysis in R using Keras (see Here) and unfortunately I am receiving error message while computing first average rmes coln <- colnames(compare_train)[4:ncol(compare_train)] cols <- map(coln, quo(sym(.))) rsme_train <- map_dbl(cols, function(col) rmse( compare_train, truth = value, estimate = !!col, na.rm = TRUE )) %>% mean() rsme_train Error message: Error in is_symbol(x) : object '.' not found There are some helpful comments at the bottom

Return three lists with foreach loop in R

江枫思渺然 提交于 2021-02-10 19:35:14
问题 I've been struggling with the workings of foreach loops in R. To speed up my code I'm trying to change my for loop into a foreach loop with %dopar%. My goal is to end up with three lists of the same length, each filled with data frames that represent scores between two users (I'm comparing three different calculation methods). My code used to be (very basic representation): for (a in 1:5) { #Just creating some sample data resultA <- data.frame(matrix(nrow = 40, ncol = 3)) resultB <- data

Getting error message while calculating rmse in a time series analysis

五迷三道 提交于 2021-02-10 19:32:36
问题 I am trying to replicate this example of time series analysis in R using Keras (see Here) and unfortunately I am receiving error message while computing first average rmes coln <- colnames(compare_train)[4:ncol(compare_train)] cols <- map(coln, quo(sym(.))) rsme_train <- map_dbl(cols, function(col) rmse( compare_train, truth = value, estimate = !!col, na.rm = TRUE )) %>% mean() rsme_train Error message: Error in is_symbol(x) : object '.' not found There are some helpful comments at the bottom

Error when trying to pass custom metric in Caret package

泪湿孤枕 提交于 2021-02-10 19:32:29
问题 Related question - 1 I have a dataset like so: > head(training_data) year month channelGrouping visitStartTime visitNumber timeSinceLastVisit browser 1 2016 October Social 1477775021 1 0 Chrome 2 2016 September Social 1473037945 1 0 Safari 3 2017 July Organic Search 1500305542 1 0 Chrome 4 2017 July Organic Search 1500322111 2 16569 Chrome 5 2016 August Social 1471890172 1 0 Safari 6 2017 May Direct 1495146428 1 0 Chrome operatingSystem isMobile continent subContinent country source medium 1