R Vetors

Vectors are a basic data object in R. There are six types of vectors, namely logical, integer, double, complex, character and raw. You can use a c() function to create vectors, and the following shows the examples. 1. Logical Vector Output: [1] TRUE FALSE [1] “logical” 2. Integer Vector Output: [1] 44 56 [1] “integer” … Read more

Categories R

Combine Vetors to a Dataframe in R

How can you combine vectors into a dataframe in R. To do that, we can use the function of data.frame() to convert vetors into a dataframe in R. The following is the example. Step 1: Generating Vetors Output: [1] “City1” “City1” “City1” “City1” “City1” “City2” “City2” “City2” “City2” “City2” [1] “store1” “store2” “store1” “store2” “store1” … Read more

Categories R

rep() Function in R (4 Examples)

rep() is a built-in R function that replicates the values in the provided vector. This tutorial shows how to use rep() function in R with 4 examples. Example 1 The following code is to repeat the number 4 twice. Output: [1] 4 4 Example 2 Output: [1] 1 2 3 1 2 3 1 2 3 … Read more

Categories R

rep() Function in R (Examples)

rep() is a built-in R function that replicates the values in the provided vector. The following shows examples of using rep() in R. Example 1 The following code is to repeat the number 4 twice. Output: [1] 4 4 Example 2 Output: [1] 1 2 3 1 2 3 1 2 3 1 2 3 Example … Read more

Categories R

How to Convert Array to Column in Pandas dataframe

You can use pd.DataFrame() function to convert an array to a column in a Pandas dataframe. The following shows examples of how to convert array from Numpy to a column in Pandas. Example 1: Single Column Step 1: Using Numpy to create an array Output: [‘City1’ ‘City1’ ‘City1’ ‘City1’ ‘City1’ ‘City2’ ‘City2’ ‘City2’ ‘City2’ ‘City2’] … Read more

How to Create an Empty Matrix in NumPy

The syntax of creating an empty array is as follows. Method 1: Full of zero numpy.zeros(shape=(n,m)) Method 2: Really empty Note that, empty, unlike zeros, does not set the array values to zero, and may therefore be marginally faster. However, it requires the user to manually set all the values in the array, and thus you … Read more

How to Convert NumPy Array to List

We can use tolist() and list() to convert an array into a list in Python. The following is the syntax. Method 1: array.tolist() Method 2: list(array) The following is to generate an array using Numpy. Array_1: [5 8 4 4] Method 1: np.tolist() list_1: [5, 8, 4, 4] Method 2: list() We can use Python … Read more

Outer Merge in Pandas

Introduction Outer Merge returns all records from both the left or right dataframes. When rows in one dataframe do not match another dataframe, the merged dataframe will have NaN for the cells. We can use how=’outer’ in merge() to outer merge two dataframes in Pandas. The basic syntax is as follows, in which df_1 and df_2 … Read more

Outer Join in Pandas

Outer Join returns all records from both the left or right dataframes. When rows in one dataframe do not match another dataframe, the joined dataframe will have NaN for cells of the unmatched rows. We can use how=’outer’ in join() to outer join two dataframes in Pandas. The basic syntax is as follows, in which df_1 … Read more

Left Merge in Pandas Python

We can use how=’left’ tells merge() to left merge two dataframes. The following is the Pandas syntax, in which df_1 and df_2 are two dataframes to be merged. df_1.merge(df_2, how=’left’, left_index=True, right_index=True) Step 1: Prepare the data to be left merged The following is the two dataframes to be left merged. df_1: Brand Location a … Read more