R How to convert data in Matrix? Factor to Integer? [closed] - r

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am having trouble operating Matrixs.
First, I want to make factor data to integer so i can operate.
Second, The First col, which shows date, should be factor. How can i change?

Try this:
d <- data.frame(1:10, letters[1:10])
data.matrix(d)
Also you can try this too :
m = matrix(scan("file.csv", what=numeric(), skip=1))
skip=1 to skip a header line.
Hope this will help you

Related

How is it possible to add 15 to every figure in a column, in a tibble? [duplicate]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I’m new to R and I’m trying to add 15 to every figure in my dataset for a specific column and was wondering how it’s possible to this. Any help would be much appreciated, thanks.
Asssuming you have a data.frame df with a column col that you want to increase:
df$col <- df$col + 15
No loop required, the fundamental objects in R are vectors.

generate all possible k-mers from a vector and also remaining in r [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Suppose we have a vector [1:10] of players, I want to generate all possible roommates for these playes (not combn(10, 2))
Can you help me?
Thank you
You can iterate over combn(with different ks)
x= 1:10
lapply(1:length(x), function(k) combn(x,k))

Create new column from two column with logic in R? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
Looking for other way than ifelse.
How to create NewColumn like this:
As displayed in your picture, you want to paste together two columns. Assuming your dataframe is called df, you can do:
df$NewColumn <- paste(df$Column2,"",df$Column1)
Which will get you the outcome in the picture.

Specific code from SAS to R [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am trying to write this (SAS) comand in R. x is a variable with this specific format: j61915035t
x1 = trim(upcase(substr(x,1,1)));
I really appreciate what you are doing in this site!
You want to remove leading/trailing blanks from a character string that is the uppercase first letter of the string x. So this should do it.
library(stringr)
x1 = str_trim(str_to_upper(str_sub(x,1,1)))

R : Do not understanding the objective of a code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Given the following setup:
area.factor <- cut(state.x77[,"Area"],
breaks=quantile(state.x77[,"Area"],c(0,.25,.75,1)),
labels=c("small","medium","large"),
include.lowest=TRUE)
state <- data.frame(pop=state.x77[,"Population"],
inc=state.x77[,"Income"],
area=area.factor,
region=state.region)
pop.area.region <- with(state,ftable(pop,area,region))
The following two lines of code are show the same result:
head(ftable(prop.table(pop.area.region,margin=2)))
head(prop.table(pop.area.region,margin=2))
I don't understand what effect adding ftable has, if any, in:
head(ftable(prop.table(pop.area.region,margin=2)))
Adding ftable witll try to coerce the pop.area.region to a ftable class. Here
No need to add ftable since pop.area.region is already an ftable.
identical(ftable(prop.table(pop.area.region,margin=2)),
prop.table(pop.area.region,margin=2))
TRUE

Resources