r

R: Loop outputting only the last iteration

廉价感情. 提交于 2021-02-11 17:03:28
问题 I have 39 json files stored in a folder. They all have three columns in common: MOVEMENT_ID , DISPLAY_NAME and geometry . I would like to arrive at a dataset containing the data from all files, organised into these columns. I am using a for loop to do so. path = "~/geoboundaries" #path to the folder where the files are stored file.names=as.list(dir(path, pattern='.json', full.names=T)) #make a list of all file names out.file=st_sf(MOVEMENT_ID=factor(), DISPLAY_NAME=factor(), geometry=st_sfc()

kable, collapse_rows and booktabs: no alignement to the top

匆匆过客 提交于 2021-02-11 17:01:26
问题 I am trying to print a data.frame in a pdf using kable and collapse_rows functions. And it did not manage to make it works. Please try the following reprex: --- title: "Example" output: bookdown::pdf_document2 --- ```{r bandIdentif, echo=F} library(dplyr);library(kableExtra) dt <- data.frame(A = c(rep("a", 2), rep("b", 3)), B = c(paste("answer", 1:5))) kable(dt, "latex") %>% collapse_rows(columns = 1, valign = "top") ``` I have updated all the packages (MaxTex and R) and Rstudio. However, the

Factoextra: How to change color of the average silhouette width in the fviz_silhouette function?

烈酒焚心 提交于 2021-02-11 16:59:12
问题 I'm very curious about the ways to override the color value of the default red dashed line for average silhouette width in the fviz_silhouette function. Just peeked the fviz_silhouette code, and it puzzling me, why the author fixed line color parameter? (Listing from the function source code.) p <- ggplot(df, mapping) + geom_bar(stat = "identity") + labs(y = "Silhouette width Si", x = "", title = paste0("Clusters silhouette plot ", "\n Average silhouette width: ", round(mean(df$sil_width), 2)

Factoextra: How to change color of the average silhouette width in the fviz_silhouette function?

给你一囗甜甜゛ 提交于 2021-02-11 16:58:41
问题 I'm very curious about the ways to override the color value of the default red dashed line for average silhouette width in the fviz_silhouette function. Just peeked the fviz_silhouette code, and it puzzling me, why the author fixed line color parameter? (Listing from the function source code.) p <- ggplot(df, mapping) + geom_bar(stat = "identity") + labs(y = "Silhouette width Si", x = "", title = paste0("Clusters silhouette plot ", "\n Average silhouette width: ", round(mean(df$sil_width), 2)

Assignment using get() and paste()

大憨熊 提交于 2021-02-11 16:57:01
问题 In my code I have to create an object assigning some values, something like this: assign(paste("a","bis",sep="."),rep(NA,5)) then I have to replace some of them, like this: get(paste("a","bis",sep="."))[1:2] <- 7:8 But I get the following error: "Error in get(paste("a", "bis", sep = "."))[1:2] <- 7:8 : target of assignment expands to non-language object". Of course the code above is a simplified version of the real one. What I'm trying to do is to build a loop which allows me to replace in a

make 'week' function biweek

☆樱花仙子☆ 提交于 2021-02-11 16:54:14
问题 Hi all this should be a straightforward question, I just can't seem to figure it out. I would like to break up this data set biweekly in order to look at the annual cycle in 2 week intervals. I do not want to summarize or aggregate the data. I would like to do exactly what the 'week' function is doing, but every 2 weeks instead. Below is an example of the data and code. Any help would be greatly appreciated! DF<-dput(head(indiv)) structure(list(event.id = 1142811808:1142811813, timestamp =

R studio: use only specific variables but being able to work on and not lose other variable information

时光毁灭记忆、已成空白 提交于 2021-02-11 16:51:39
问题 Hi everyone I need a little bit of help with a problem I'm facing, which I'm sure is quite simple but I can't seem to be able to solve it by myself. Basically this is my dataset: Age Gender Group V1 V2 V3 V4 V5 20 1 1 2 1 4 21 2 1 2 2 1 35 2 2 2 1 22 2 1 2 I see that many suggest subset/select function to perform analysis with specific variables, but what I need is to work from v1 to v5 to understand how many row to delete cause of the missing data but without losing the age, gender and group

splitting list into its components and combine to form another list in R [duplicate]

房东的猫 提交于 2021-02-11 16:50:37
问题 This question already has answers here : How to combine two lists in R (3 answers) Closed 12 months ago . I have list 1: l1 <- list(letters[1:26]) I have list 2: l2 <- list(c(1:26)) How would I combine l1 and l2 into a new list l4 with 52 elements: the first 26 elements are the elements of l1 and the next 26 are the elements of l2 ? 回答1: You could use c to combine them l4 <- c(l1[[1]], l2[[1]]) Or with unlist l4 <- c(unlist(l1), unlist(l2)) Maybe you want to wrap it in list l4 <- list(c(l1[[1

R methods on nested class instances (OOP)

一个人想着一个人 提交于 2021-02-11 16:49:11
问题 I have my student S3 class # a constructor function for the "student" class student <- function(n,a,g) { # we can add our own integrity checks if(g>4 || g<0) stop("GPA must be between 0 and 4") value <- list(name = n, age = a, GPA = g) # class can be set using class() or attr() function attr(value, "class") <- "student" value } I want to define the class groupofstudents : stud1 <- student("name1", 20, 2.5) stud2 <- student("name2", 21, 3.5) groupofstudents <- function(firststud = stud1,

splitting list into its components and combine to form another list in R [duplicate]

做~自己de王妃 提交于 2021-02-11 16:47:53
问题 This question already has answers here : How to combine two lists in R (3 answers) Closed 12 months ago . I have list 1: l1 <- list(letters[1:26]) I have list 2: l2 <- list(c(1:26)) How would I combine l1 and l2 into a new list l4 with 52 elements: the first 26 elements are the elements of l1 and the next 26 are the elements of l2 ? 回答1: You could use c to combine them l4 <- c(l1[[1]], l2[[1]]) Or with unlist l4 <- c(unlist(l1), unlist(l2)) Maybe you want to wrap it in list l4 <- list(c(l1[[1