Found 26504 Articles for Server Side Programming

How to check matrix values equality with a vector values in R?

Nizamuddin Siddiqui
Updated on 01-Nov-2021 10:44:14

214 Views

If we have a vector called V that contains five values and a matrix say M that contains five columns and we want to check whether first value in the vector is present in the first column of each row in the matrix and so on for each value in the vector then we can use the below command −t(t(M)==V)Example 1Consider the below matrix and vector −M1

Find the row means for columns starting with a string in an R data frame.

Nizamuddin Siddiqui
Updated on 01-Nov-2021 10:23:12

937 Views

To find the row means for columns starting with specific string in an R data frame, we can use mutate function of dplyr package along with rowMeans function.For Example, if we have a data frame called df that contains three columns say x1_x2, x1_x3, x1_x2 and we want to find the row means for columns x1_x2 and x1_x3 then, we can use the below command −df%%mutate(X1_Cmbn=select(.,starts_with("x1_")) %% rowMeans())Example 1Following snippet creates a sample data frame −Grp1_x

How to find the row mean for selected columns in R data frame?

Nizamuddin Siddiqui
Updated on 01-Nov-2021 09:56:41

3K+ Views

To find the row mean for selected columns in R data frame, we can use mutate function of dplyr package along with rowMeans function.For Example, if we have a data frame called df that contains three columns say X, Y, and Z then mean of each row for columns X and Y can be found by using the below command −df %% mutate(X_Y_Mean=select(.,c("X","Y")) %% rowMeans())Example 1Following snippet creates a sample data frame −x1

Find the column and row names in the R data frame based on condition.

Nizamuddin Siddiqui
Updated on 01-Nov-2021 08:28:55

8K+ Views

To find the column names and row names in an R data frame based on a condition, we can use row.names and colnames function. The condition for which we want to find the row names and column names can be defined inside these functions as shown in the below Examples.Example 1Following snippet creates a sample data frame −x1

How to find the groupwise order of values in an R data frame?

Nizamuddin Siddiqui
Updated on 01-Nov-2021 08:22:21

587 Views

To find the groupwise order of values in an R data frame, we can use mutate function of dplyr package along with rank function and grouping will be done with the help of group_by function.For Example, if we have a data frame called df that contains two columns say Group and DV then we can find the groupwise order of DV values by using the command given below −df%%group_by(Group)%%mutate(Order=rank(DV))Example 1Following snippet creates a sample data frame −Group

How to create correlation matrix plot without variables labels in R?

Nizamuddin Siddiqui
Updated on 12-Nov-2021 04:06:03

494 Views

To create correlation matrix plot without variables labels in R, we can use tl.pos argument set to n.For Example, if we have a correlation matrix say M then we can create the correlation matrix plot without variables labels by using the below command −corrplot(M,tl.pos='n')ExampleFollowing snippet creates a sample data frame −x

How to get the current username and directory in Golang?

Kiran Kumar Panigrahi
Updated on 01-Nov-2021 07:58:39

7K+ Views

Sometimes there are cases where we want to know which user is executing the current program and in which directory and we can get all these details with the help of the user package that is present inside the os package of Go's standard library.In this article, we will explore three such cases, where first, we will log out the username who is executing the current process and then we will log out the name along with the id and finally, we will log out from the directory in which the current program is located.Getting the UsernameTo get the username, ... Read More

How to get the size of an array or a slice in Golang?

Kiran Kumar Panigrahi
Updated on 01-Nov-2021 07:47:24

936 Views

In case we want to get the size of an array or a slice, we can make use of the built-in len() function that Go provides us with.Example 1Let's first explore how to use the len function with an array. Consider the code shown below.package main import (    "fmt" ) func main() {    fmt.Println("Inside the main function")    arr := [3]int{1, 2, 3}    fmt.Println("The length of the array is:", len(arr)) }In the above code, we are using the len function on the array defined as arr.OutputIf we run the command go run main.go ... Read More

How to close a channel in Golang?

Kiran Kumar Panigrahi
Updated on 01-Nov-2021 07:45:20

3K+ Views

We can close a channel in Golang with the help of the close() function. Once a channel is closed, we can't send data to it, though we can still read data from it. A closed channel denotes a case where we want to show that the work has been done on this channel, and there's no need for it to be open.We open the channel the moment we declare one using the make keyword.ch := make(chan int)Example 1Let's consider a very simple example, in which we will create a buffered channel and then pass data to it and then close ... Read More

Extract columns with a string in column name of an R data frame.

Nizamuddin Siddiqui
Updated on 01-Nov-2021 07:58:40

4K+ Views

To extract columns with a particular string in column name of an R data frame, we can use grepl function for column names and then subset the data frame with single square brackets.For Example, if we have a data frame called df and we want to extract columns that has X in their names then we can use the command mentioned below −df[grepl("X",colnames(df))]Example 1Following snippet creates a sample data frame −Students_Score

Advertisements