dataframe - mapply for SparkR R -
i have spark dataframe "a" header follows
c1 | c2 | c3 | c4 i1 | 12 | 31 | 4 i2 | 14 | 32 | 13 i3 | 13 | 33 | 15 i4 | 16 | 29 | 25 i5 | 18 | 30 | 73 i6 | 17 | 36 | 19
column 2 (c2) smaller c3
i want compare c4 c3 , c2 following logic: if c4 between c2 , c3 return 1 else return 2
and add new column dataframe
i can mapply when there no spark involved. how can in sparkr?
you should able ifelse statement
df_a <- data.frame(c1 = c('i1', 'i2', 'i3', 'i4', 'i5', 'i6'), c2 = c(12, 14, 13, 16, 18, 17), c3 = c(31, 32, 33, 29, 30, 36), c4 = c(4, 13, 15, 25, 73, 19)) <- as.dataframe(df_a) a$c5 <- ifelse(a$c4 > a$c2 & a$c4 < a$c3, 1, 2) head(a) c1 c2 c3 c4 c5 1 i1 12 31 4 2 2 i2 14 32 13 2 3 i3 13 33 15 1 4 i4 16 29 25 1 5 i5 18 30 73 2 6 i6 17 36 19 1
Comments
Post a Comment