Convert Data Frame to Matrix in R (2 Examples) | Numeric & Character Matrices | as.matrix & apply

  Рет қаралды 7,889

Statistics Globe

Statistics Globe

Күн бұрын

How to transform data frames to matrices in the R programming language. More details: statisticsglob...
R code of this video:
my_df <- data.frame(x1 = 3:8, # Create data frame
x2 = 10:5,
x3 = 4)
my_df # Print data frame
class(my_df) # Class of data
my_mat <- as.matrix(my_df) # Convert data frame to matrix
my_mat # Print matrix
class(my_mat) # Class of data
my_df_fac <- my_df # Duplicate data
my_df_fac$x2 <- as.factor(my_df_fac$x2) # Convert column to factor
my_mat_fac <- as.matrix(my_df_fac) # Using as.matrix function
my_mat_fac # Print character matrix
my_mat_num <- apply(as.matrix.noquote(my_df_fac), # Using apply function
2,
as.numeric)
my_mat_num # Print numeric matrix
Follow me on Social Media:
Facebook: / statisticsglobecom
LinkedIn: / statisticsglobe
Patreon: / statisticsglobe
Pinterest: www.pinterest....
Reddit: / joachimschork
Twitter: / joachimschork

Пікірлер: 8
@nakitacally4612
@nakitacally4612 2 жыл бұрын
Dude, you are saving my academic life. 😅 Thanks, bro🙏
@matthias.statisticsglobe
@matthias.statisticsglobe 2 жыл бұрын
You are welcome Nakita! Thanks for the nice words, it's always good to hear that the videos are helpful!
@anycaroliny7900
@anycaroliny7900 3 жыл бұрын
Thank you. I'm studying Applied statistics and this was very helpful.
@StatisticsGlobe
@StatisticsGlobe 3 жыл бұрын
Great to hear Any! Thank you for the nice comment! :)
@cavabingaMAN
@cavabingaMAN 3 жыл бұрын
The idea for the next videos: you could review and explain difficult SO questions & answers. Also, you could explain and review some shiny code.
@StatisticsGlobe
@StatisticsGlobe 3 жыл бұрын
Hey, actually I'm working a lot with Shiny at the moment, and I have planned to release tutorials on Shiny in the future :) Thanks a lot for the suggestions!
@vanhoot2234
@vanhoot2234 2 жыл бұрын
Do you have a video that does the opposite
@StatisticsGlobe
@StatisticsGlobe 2 жыл бұрын
Hey, yes I do. Please have a look here: statisticsglobe.com/convert-matrix-to-data-frame-in-r
Converting between data frames and vectors
10:25
weecology
Рет қаралды 2,3 М.
Create and Work with Vectors and Matrices in R | R Tutorial 1.4 | MarinStatslectures
8:35
MarinStatsLectures-R Programming & Statistics
Рет қаралды 446 М.
Minecraft: Who made MINGLE the best? 🤔 #Shorts
00:34
Twi Shorts
Рет қаралды 46 МЛН
100km/h Reflex Challenge 😱🚀
00:27
Celine Dept
Рет қаралды 156 МЛН
And what’s your height? 😁 @karina-kola
00:10
Andrey Grechka
Рет қаралды 52 МЛН
Chi Squared Test using R programming
16:59
R Programming 101
Рет қаралды 42 М.
Insane Theoretical Physics Discussion with ChatGPT and DeepSeek
4:59
Unzicker's Real Physics
Рет қаралды 40 М.
Handling NA in R | is.na, na.omit & na.rm Functions for Missing Values
6:19
R Basics 11 - Arrays
7:59
Maths Partner
Рет қаралды 15 М.
Loop Through Column and Rows of a Dataframe in R
9:52
The Data Hall
Рет қаралды 861
How To... Remove Records with Missing Data in R #74
6:54
Eugene O'Loughlin
Рет қаралды 10 М.
What if all the world's biggest problems have the same solution?
24:52
Minecraft: Who made MINGLE the best? 🤔 #Shorts
00:34
Twi Shorts
Рет қаралды 46 МЛН