This question already has answers here:
Create a vector that contains the first 10 powers of 2, then the first 10 powers of 3 by R language
(2 answers)
Closed 1 year ago.
How can I create this sequence in R?
I've been watching some guides but these are simple sequences.
It is vectorized. We can do
2^(1:10)/(1:10)
Related
This question already has answers here:
Getting the last n elements of a vector. Is there a better way than using the length() function?
(6 answers)
Closed 5 years ago.
I am working in a dataframe in R and I want to access the last 5 objects of a particular column in a dataframe.How do i go about it??
One option is tail(dataframe$column, 5)
This question already has answers here:
Dividing a vector into categories
(1 answer)
How to create a categorical variable in R with unequal categoris [closed]
(1 answer)
R if else with for loop [duplicate]
(3 answers)
Closed 5 years ago.
I'm programming in R.I need to divided a vector into x partitions(eg,x=4),and get the partition number of the vector, something like this...
a <- data.frame(x=1:20)
a$numofpartition<-ifelse(a$x<6,1,ifelse(a$x<11,2,ifelse(a$x<16,3,4)))
As the code,I divided a$x into 4 partitions,and get the partition number for each x, any functions in R could do this? Thank you!
This question already has answers here:
Getting the last n elements of a vector. Is there a better way than using the length() function?
(6 answers)
Closed 5 years ago.
suppose I have daily time series data under variable name "prices", but im only interested in the past 100 days. How would i extract the last 100 elements from this variable?
Something equivalent to python's prices[-100:] but for R?
If it's a vector:
tail(prices, 100)
This question already has answers here:
How to get all possible combinations of n number of data set?
(2 answers)
How to calculate combination and permutation in R?
(6 answers)
Closed 5 years ago.
I am getting a tough time in selecting the combinations of factors.
I have a vector as ("Ryan", "Leo", "Jack","Harry","Edd").
I want to get the list of of all combinations taken 3 of the names once.
I want to do it in R. Probably a resultant matrix will help me.
We can use combn
t(combn(vec1, 3))
This question already has answers here:
Generate a dummy-variable
(17 answers)
Closed 6 years ago.
I am doing an assignment with the built-in "SWISS" dataset, and where the value is greater than 50 I need to create a binary variable taking 1
I have a feeling that I might have to use the subset command, but I am lost as how to implement it.
using dplyr
swiss %>%
mutate(aggGreaterThan50 = (Agriculture > 50) * 1)