Regarding 1:
It depends what you want to do, if you want to replace value by value separately, you have to tell R
to go trough every entry step by step. This can be achieved by a for
loop or with while
for example. However, since your comparison (myData[,1] > meanvalue
) results in a vector of correct length, you can use the following alternative as well:
myData$meanSplit <- ifelse(myData[,1] > mean_val, 'Less', 'More')
Regarding 2:
Using [[i]]
means "take the ith element of the object", whereas [[i,1]]
means "take the element in ith row in first column". You can use double squared brackets to extract exactly one element, whereas single squared brackets can be used to extract an element (e.g. takes my_mat[[i]]
and my_mat[i]
the ith element of a matrix) or a complete row (my_mat[i,]
) or a complete column (my_mat[,i]
). However, since you use [[]]
for lists, it is more convenient (I think) to use [[]]
for single elements and []
for a complete row or column.
Regarding 3:
The given breaks define intervals of the form (a,b]. So if you give a vector of value to cut, e.g. c(a,b,c,d)
with a,b,c,d \in \mathbb{R}, you will have a set of intervalls as follows:
I = \left\{(a,b], (b,c], (c,d]\right\}
This is the default behaviour which can be adjusted of course. However, in the end these are three intervalls, hence for four breaking points, you only need to have three labels which label the intervalls.
Kind regards