R Matrix Package: Meaning of the attributes in the dgCMatrix class for sparse...
I've looked at the Matrix package and at their slides. I was trying to understand what is the intution and the meaning behind the arguments in the dgCMatrix class. I understand that@i gives the...
View ArticleHow to plot a network degree to node size and eigenvector to x axis and an...
I would like to set my network nodes size to degree centrality and the distribution on the x axis to eigenvector centrality while I distribute an attribute on the y axis. I have the following code: u...
View ArticleWriting a custom model for gnm package, but need a function not in derivative...
I am trying to write a custom model for gnm, to fit Voigt profiles. I have definedlibrary(gnm) ; library(RcppFaddeeva) VOIGT <- function(x) { list(predictors=list(Center=1, Sigma=1, Gamma=1,...
View ArticleReturn a list with named elements from function
QuestionI have a function like this:myfunc <- function(x){ a1 = 1 a2 = c(2,4) a3 = data.frame(x = 1:10) ... an = 'str' res = list(a1 = a1,a2 = a2,..., an=an) return(res) } As we can see, I return my...
View ArticleHow to calculate properly average values of a variable in `df1` using data...
I have a dataframe df1 that summarizes different observations of an individual ID overtime but rounded at fixed 45-minutes intervals starting at 00:00:00 (00:00:00, 00:45:00, etc.). As an...
View ArticleRead multiple csv files (and skip 2 columns in each csv file) into one...
I have a folder of about 100 csv files and I want to read them into one dataframe in R. I kind of know how to do this but I have to skip the first two columns in every csv file and that is the part I...
View ArticleCalculating stock's return by a variable interval in data.table
Here is my data.tablestructure(list(index = structure(c(17007, 17008, 17009, 17010, 17011, 17014, 17015, 17016, 17017), tzone = "UTC", tclass = "Date", class = "Date"), close = c(97.339996, 96.669998,...
View ArticleHighlighting One of my Line Graphs in ggplot
Here is a link to my example dataWhat I want to do is create one graph with of only the values when the "Number" column has a 1 and with X on the X-Axis, Y on the Y-Axis and have multiple different...
View ArticleJoin two data sets based on one column [closed]
I have two data sets (DF1, DF2) of uneven rows and I am trying to merge the two using the unique ID column that is present in both data sets. My condition is that I only want rows with matching IDs...
View ArticleSummarise all confidence intervals
library(gmodels) library(dplyr) df<- data.frame(a=1:5,b=6:10,c=11:15) df %>% summarise_all(funs(mean,sd,min,max)) At the moment I have a df which is producing a summary of the mean, sd, min, and...
View ArticleChanging many column types in r with purrr
str(mtcars)How do I make a list of some column names and change them to numeric or character. For example say I want to change c("am", "gear") into character columns.I am looking for a solution e.g....
View ArticleConvert long to wide with variable number of columns
Given the following data in long form, I would like to create a wide dataset with one row for each srdr_id, and a separate column for each arm_name as below.Desired output:srdr_id c1 c2 c3 174212 TAU...
View ArticleWrite a function to calculate the square of the first k elements of a vector
I am trying to calculate the square of the first k elements of a vector v. If k is greater than the length of the vector n, then set k = n.myfun1 = function(v,k){ p = ifelse(k > length(v), k =...
View ArticleOperations on single row in dplyr [duplicate]
This question already has an answer here:dplyr mutate/replace several columns on a subset of rows 12 answersIs it possible to performa dplyr operations with pipes for single rows of a dataframe? For...
View ArticleError: faceting variables must have at least one value
I have the following dataset:Col1 Col2 Col3 Col4 Col5 Col6 4439.5 6.5211 50.0182 29.4709 -0.0207 0.0888 4453 25.1186 46.5586 34.1279 -0.0529 0.082 4453.5 24.2974 46.6291 30.6281 -0.057 0.0809 4457.5...
View ArticleExtract certain number patterns from an integer in a vector
For data Quakes that looks like: Date Latitude Longitude M 1 18001011 ... 2 18001122 3 18030000 4 19001010 ... class(Quakes$Date) gives "integer" and without using regular expressions to grab patterns,...
View ArticleHow do visualize the rise or decline of occurrence of a word in a data set...
Im trying to make a graph like this (actually single line for simplicity sake) Given an input word like 'M4M" and a data set file (csv) like this1529972216.0,Seeking Black M4M 1529972047.0,Looking for...
View ArticleHow to place a condition on a variable [duplicate]
This question already has an answer here:Finding which element of a vector is between two values in R 3 answersI have a sampling function of:z = rnorm(n, 0.3, 1) And would like my variable f to equal 1...
View ArticlePlot three values x-axis [closed]
I have a data frame and I would like to plot as show the Figure 1.My data frame has three column.Each line must be plot on the same X-axis (three values by X-axis, as show the Figure 1).It has a line...
View ArticleR: Merging rows to export to excel
I have to merge the rows of excel if the values in a column are identical (within a Unique Identifier group). I've attached a photo of the current openxlsx output and the desired one. I know in SAS you...
View Article