How to create level in the split function in R

#1

I am studying split loop function and when I am studying about its syntax .
split(x,f)
f-is the level
I want to know that how to create the level in the split function
for example I have created the x
x<-c(runif(10),rnorm(10))
I want to know the level in the x

#2

Hello @sid100158,

Mentioned below is one way:

As you can see that data is divided into groups based on the ‘levels’ of factors that the data contains.So a condition for applying split based on a column (f) is that it should be a factor.
Hope this helps!!

#3

You can also use it for multiples of the factor
i.e.
if x is as follows:

x<-c(runif(10),rnorm(10))

and f is as follows:

f<-seq(9.1,10,.1)

The output will be as follows:
\$`9.1`
[1] 0.5577966 -0.2955505

\$`9.2`
[1] 0.0001061496 -0.4849098741

\$`9.3`
[1] 0.5336780 -0.6544547

\$`9.4`
[1] 0.5368596 0.6218630

\$`9.5`
[1] 0.6210515 0.7958973

\$`9.6`
[1] 0.2126130 0.9363195

\$`9.7`
[1] 0.2507135 1.8690868

\$`9.8`
[1] 0.04564947 1.15263353

\$`9.9`
[1] 0.4324564 -1.9403119

\$`10`
[1] 0.25930467 -0.09644921

Hope this helps!