[Solved] scatter plot of different color in R

Your question is not very clear, but assuming your data is in df, it sounds like you want something like this to get started: plot(1:5, df$var1, pch=19, col=”blue”, ylim=c(0,80)) points(1:5, df$var2, pch=19, col=”red”) As for the trend of the data, what do you mean? A trend for each line? Or do you actually want to … Read more

[Solved] Subset Columns in R using which

What is wrong is that you are using the condition which(ff[,1:ncol(ff)]>2.5) to choose rows (we know that there is only a single row) rather than columns. Hence, ff[, which(ff[,1:ncol(ff)]>2.5)] would work. Or simply ff[, ff > 2.5] 3 solved Subset Columns in R using which

[Solved] Several questions on ggplot2 [closed]

Have a look at scale_color_manual, the examples should be sufficient. The general structure of tweaking any scale in ggplot2 is to use the appropriate scale function: scale_{aes_name}_{scale_type}, where aes_name can be color, x, or any other aeshetic, and where scale_type can be continuous, discrete, manual, etc. Googling for ggplot2 legend position led me to this … Read more

[Solved] R subset based on range of dates [closed]

Are you asking something like the following? Let’s say your initial dataframe is df, which is the following: df A B C 1 2016-02-16 2016-03-21 2016-01-01 2 2016-07-07 2016-06-17 2016-01-31 3 2016-05-19 2016-09-10 2016-03-01 4 2016-01-14 2016-08-21 2016-04-01 5 2016-09-02 2016-06-15 2016-05-01 6 2016-05-09 2016-07-17 2016-05-31 7 2016-06-13 2016-06-23 2016-07-01 8 2016-09-17 2016-03-11 2016-07-31 9 … Read more

[Solved] Removing different words form a document using R console

A simple way would be to use gsub(paste0(‘\\b’, YOURVECTOROFWORDSTOREMOVE, ‘\\b’, collapse=”|”),”,YOURSTRING) which replaces every occurence of the words in the vector surrounded by either end/beginning characters or whitespace with a single space. but you might want to look at the tm package and work with a corpus object if you have many files like this. … Read more

[Solved] How to create a map with zipcode dataset? ( US Zipcode ) [closed]

Try the following code which I modified from January at how do I map (on a geographical map) data in R just given the US Zipcodes: pdf(“myzipcodes.pdf”) library(maps) map(database=”usa”)# national boundaries library(zipcode) data(“zipcode”) myzips <- c(“22313″,”83701″,”32301”) selected <- zipcode[ zipcode$zip %in% myzips, ] points( selected$longitude, selected$latitude, pch= 19, cex= 2 ) text( selected$longitude, selected$latitude, selected$zip, … Read more

[Solved] Selecting rows in R with “Yes” in one column of a set of columns, and NOT “Yes” in all columns of another set of columns

as long as you have the dataframe organized the way you do now i.e., comp1type1,comp1type2,comp1type3,comp2type1,…,comp[I]type[J]. I am sure you can use the following method. ncomp <- 20 ntype <- 3 vecone <- df[,seq(1,ncomp*ntype,ntype)] vectwo <- df[,seq(2,ncomp*ntype,ntype)] vecthree <- df[,seq(3,ncomp*ntype,ntype)] # now that we have the vectors of types seperated into data.frame’s # it’ll be easier … Read more

[Solved] Find new and active user each week from user_id and date

so I managed to calculate the count_new by checking the first appearance of a user_id and then merging with initial data adding a column that tell if a user is new by date and id then I counted the new by date: library(dplyr) firstshow<-Orders %>% group_by(user_id) %>% arrange(date) %>% slice(1L) %>% mutate(new = “new”) newdata<-merge.data.frame(Orders,firstshow,by=c(“date”,”user_id”),all … Read more

[Solved] In R; I would like to do something in R rather than excel because excel can’t handle the calculation. In excel the calculation is: =A2+SUM($B$2:B2)

Look into dplyr https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html install.packages(“dplyr”) library(dplyr) df <- df %>% mutate(phys_pos=cumsum(length)+position) I am assuming your data.frame is named df Or with base R df$phys_pos <- cumsum(df$length) + df$position 1 solved In R; I would like to do something in R rather than excel because excel can’t handle the calculation. In excel the calculation is: =A2+SUM($B$2:B2)

[Solved] Make columns in data frame equal to median, mean, etc.? (R) [closed]

Your dataframe: df<-data.frame(x=c(1, 3 , 5), y=c(1, 1, 2), z=c(256, 5, 4)) Using dplyr/tidyr: df1<-df%>%gather(var,val,x:z)%>%group_by(var)%>%summarise(max=max(val),min=min(val),avg=mean(val),median=median(val)) you can extend this to any number of summary stats. # A tibble: 3 × 5 var max min avg median <chr> <dbl> <dbl> <dbl> <dbl> 1 x 5 1 3.000000 3 2 y 2 1 1.333333 1 3 z … Read more

[Solved] How to replace a value by another within a variable in R?

You can use this approach to get what you need: df = within(df, { variable[variable == “string”] = “string2” variable[is.na(variable)] = mean(variable) }) The trick here is that you can create a subset using [] and assign values again to that subset using [] =. 2 solved How to replace a value by another within … Read more