r

Removing text containing non-english character

丶灬走出姿态 提交于 2021-02-16 11:58:46
问题 This is my sample dataset: Name <- c("apple firm","苹果 firm","Ãpple firm") Rank <- c(1,2,3) data <- data.frame(Name,Rank) I would like to delete the Name containing non-English character. For this sample, only "apple firm" should stay. I tried to use the tm package, but it can only help me delete the non-english characters instead of the whole queries. 回答1: I would check out this related Stack Overflow post for doing the same thing in javascript. Regular expression to match non-English

Create a bin for anything above X value in GGPlot2 Histogram

99封情书 提交于 2021-02-16 10:22:12
问题 Using ggplot2 , I want to create a histogram where anything above X is grouped into the final bin. For example, if most of my distribution was between 100 and 200, and I wanted to bin by 10, I would want anything above 200 to be binned in "200+". # create some fake data id <- sample(1:100000, 10000, rep=T) visits <- sample(1:1200,10000, rep=T) #merge to create a dataframe df <- data.frame(cbind(id,visits)) #plot the data hist <- ggplot(df, aes(x=visits)) + geom_histogram(binwidth=50) How can

remove leading 0s with stringr in R

醉酒当歌 提交于 2021-02-16 10:19:11
问题 I have the following data id 00001 00010 00022 07432 I would like to remove the leading 0 s so the data would like like the following id 1 10 22 7432 回答1: Using the new str_remove function in stringr : id = str_remove(id, "^0+") 回答2: Here is a base R option using sub : id <- sub("^0+", "", id) id [1] "1" "10" "22" "7432" Demo 回答3: We can just convert to numeric as.numeric(df1$id) [#1] 1 10 22 7432 If we require a character class output, str_replace from stringr can be used library(stringr)

R: How can I remove rows from all the data frames in this list?

可紊 提交于 2021-02-16 09:15:24
问题 Say I have some data created like this n <- 3 K <- 4 dat <- expand.grid(var1=1:n, var2=1:K) dat looks like this: var1 var2 1 1 1 2 2 1 3 3 1 4 1 2 5 2 2 6 3 2 7 1 3 8 2 3 9 3 3 10 1 4 11 2 4 12 3 4 I want to remove some rows from both data frames in the list at the same time. Let's say I want to remove the 11th row, and I want the 'gap' to be filled in, so that now the 12th row will become the 11th row. I understand this is a list of two data frames. Thus the advice here does not apply, since

R: How can I remove rows from all the data frames in this list?

依然范特西╮ 提交于 2021-02-16 09:15:13
问题 Say I have some data created like this n <- 3 K <- 4 dat <- expand.grid(var1=1:n, var2=1:K) dat looks like this: var1 var2 1 1 1 2 2 1 3 3 1 4 1 2 5 2 2 6 3 2 7 1 3 8 2 3 9 3 3 10 1 4 11 2 4 12 3 4 I want to remove some rows from both data frames in the list at the same time. Let's say I want to remove the 11th row, and I want the 'gap' to be filled in, so that now the 12th row will become the 11th row. I understand this is a list of two data frames. Thus the advice here does not apply, since

Expand/Collapse Shiny selectInput function

我的梦境 提交于 2021-02-16 09:01:52
问题 I would like to find a resource that would allow my Shiny selectInput function to expand/collapse based on the category headings that I have created. I have searched through some bootstrap resources, but am not yet successful. Please forgive my minimal working example, I acknowledge that there may be more efficient ways to provide a MWE. Thanks for any advice you can offer. library(shiny) library(tidyverse) #create a quick dataset to plot schools <- as.data.frame(table( c('Adams', 'Van Buren'

Expand/Collapse Shiny selectInput function

那年仲夏 提交于 2021-02-16 08:59:45
问题 I would like to find a resource that would allow my Shiny selectInput function to expand/collapse based on the category headings that I have created. I have searched through some bootstrap resources, but am not yet successful. Please forgive my minimal working example, I acknowledge that there may be more efficient ways to provide a MWE. Thanks for any advice you can offer. library(shiny) library(tidyverse) #create a quick dataset to plot schools <- as.data.frame(table( c('Adams', 'Van Buren'

Find uniqueness in data frame withe rows NA?

柔情痞子 提交于 2021-02-16 08:54:51
问题 I have a data frame like below. I would like to find unique rows (uniqueness). But in this data I have 'NA'. I like if all value in one row with NA value is the same with other rows (like rows: 1,2,5) I want to ignore it, but if not same (like rows : 2,4) I like to keep it as unique row. For example, in rows 1 ,2 and 6 all values except NA are the same so because NA can be value '1 and 3' I like to remove this row and just keep row 2. Also, in row 6 values 2 and 3 (exclude NA) are the same as

How to plot classification borders on an Linear Discrimination Analysis plot in R

有些话、适合烂在心里 提交于 2021-02-16 08:54:47
问题 I have used a linear discriminant analysis (LDA) to investigate how well a set of variables discriminates between 3 groups. I then used the plot.lda() function to plot my data on the two linear discriminants (LD1 on the x-axis and LD2 on the y-axis). I would now like to add the classification borders from the LDA to the plot. I cannot see a argument in the function that allows this. The partimat() function allows visualisation of the LD classification borders, but variables are used as the x

How do i load data set part of the MASS library in R?

时间秒杀一切 提交于 2021-02-16 08:00:49
问题 I am working through this book dealing with statistical learning/machine learning and R. One of the problem states: To begin, load in the Boston data set. The Boston data set is part of the MASS library in R. library (MASS) Now the data set is contained in the object Boston . Read about the data set: ?Boston I don't understand the syntax library(MASS) . How do I get the Boston data set from this? I've tried Boston=library(MASS) but that gives me an array of words: "MASS" "stats" "graphics"