@@ -24,16 +24,19 @@ sparkR.session()
24
24
df <- read.json(" examples/src/main/resources/people.json" )
25
25
26
26
# Displays the content of the DataFrame
27
+ head(df )
28
+
29
+ # Another method to print the first few rows and optionally truncate the printing of long values
27
30
showDF(df )
28
31
# $example off:create_DataFrames$
29
32
30
33
31
- # $example on:untyped_transformations $
34
+ # $example on:dataframe_operations $
32
35
# Create the DataFrame
33
36
df <- read.json(" examples/src/main/resources/people.json" )
34
37
35
38
# Show the content of the DataFrame
36
- showDF (df )
39
+ head (df )
37
40
# # age name
38
41
# # null Michael
39
42
# # 30 Andy
@@ -46,31 +49,31 @@ printSchema(df)
46
49
# # |-- name: string (nullable = true)
47
50
48
51
# Select only the "name" column
49
- showDF (select(df , " name" ))
52
+ head (select(df , " name" ))
50
53
# # name
51
54
# # Michael
52
55
# # Andy
53
56
# # Justin
54
57
55
58
# Select everybody, but increment the age by 1
56
- showDF (select(df , df $ name , df $ age + 1 ))
59
+ head (select(df , df $ name , df $ age + 1 ))
57
60
# # name (age + 1)
58
61
# # Michael null
59
62
# # Andy 31
60
63
# # Justin 20
61
64
62
65
# Select people older than 21
63
- showDF (where(df , df $ age > 21 ))
66
+ head (where(df , df $ age > 21 ))
64
67
# # age name
65
68
# # 30 Andy
66
69
67
70
# Count people by age
68
- showDF (count(groupBy(df , " age" )))
71
+ head (count(groupBy(df , " age" )))
69
72
# # age count
70
73
# # null 1
71
74
# # 19 1
72
75
# # 30 1
73
- # $example off:untyped_transformations $
76
+ # $example off:dataframe_operations $
74
77
75
78
76
79
# $example on:sql_query$
0 commit comments